Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
DrGenious
Creator
Creator

Header and Footer

Hey,

 

I created a file in tjavarow the code is below:

 

File OutputFile= new File(context.main_path + "\\Successful\\" + (((String)globalMap.get("tWaitForFile_1_FILENAME")).split("\\.",2))[0] + ".csv");

if (OutputFile.createNewFile()){
System.out.println("File is created!");
}else{
System.out.println("File already exists!");
}

FileWriter writer = new FileWriter(OutputFile);
writer.write(input_row.anumber + "~" +input_row.bnumber + "~");
writer.close();

Now I want to put a header with the name of the file and a footer with the total rows. Also it prints only one row from the 23 rows. How can I write them all ? Please help me .

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Use standard row names such as row1, row2 and so on instead of input_row/output_row.

For the header, something like this should work:

 

writer.write((((String)globalMap.get("tWaitForFile_1_FILENAME")).split("\\.",2))[0] + ".csv");
// declare line counter
int counter = 0;
// don't close the file
// writer.close();

 

In the main part, add 1 to the counter and write the content of current row:

 

counter++;
// write content
writer.write(row1.anumber + "~" row1.bnumber + "~" + row1.whatYouWant + "~" + "...and so on...");

 

Then in the footer you can write the counter value and close the output file:

 

writer.write("" + counter);
writer.close();

This should be ok for your use case (or not too far, I didn't try it).

 

View solution in original post

4 Replies
TRF
Champion II
Champion II

Use tJavaFlex instead of tJavaRow.
Start part will start once with the subjob and will be used to create the file and write the header Line.
Main part will start for each row and will be used to write content.
End part will start once when the subjob ends and will be used to write the foirer Line.
DrGenious
Creator
Creator
Author

@TRF 

Can tjavaflex read input_row ? Also  I dont know how to write the header and the footer. Is it possible to show me? 

TRF
Champion II
Champion II

Use standard row names such as row1, row2 and so on instead of input_row/output_row.

For the header, something like this should work:

 

writer.write((((String)globalMap.get("tWaitForFile_1_FILENAME")).split("\\.",2))[0] + ".csv");
// declare line counter
int counter = 0;
// don't close the file
// writer.close();

 

In the main part, add 1 to the counter and write the content of current row:

 

counter++;
// write content
writer.write(row1.anumber + "~" row1.bnumber + "~" + row1.whatYouWant + "~" + "...and so on...");

 

Then in the footer you can write the counter value and close the output file:

 

writer.write("" + counter);
writer.close();

This should be ok for your use case (or not too far, I didn't try it).

 

TRF
Champion II
Champion II

Did this help?

If so, thanks to mark your case as solved (Kudos also accepted).