Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Append Header row to the existing excel file dynamically

Hi All,

 

I want to add a header dynamically in my CSV file

below is my CSV File which i get after my mapping.In that first row will be added dynamically . FUEL should be taken from sheetname and system date and then the count of the row in output file

How can i achieve it?

 

0683p000009M2X6.png

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

OK, this is how I would do it.

You will need the tHashInput and tHashOutput components for this. If you do not have those available, you will need to find them. Take a look here for that...

 

https://community.talend.com/t5/Migration-Configuration-and/Where-are-the-tHashInput-and-tHashOutput...

 

Your job will look like below.

 

0683p000009M2Iy.png

The top subjob will be pretty much like yours is now, but you will replace the tFileOutputDelimited with a tHashOutput.

The next subjob uses a tFixedFlowInput with 2 columns. One for row count and one for file name. You can get the row count using a globalMap variable like this....

((Integer)globalMap.get("tFileInputExcel_1_NB_LINE"))

....check the name of your tFileInputExcel. Mine is called tFileInputExcel_1. Change the above variable key with the name of your component.

The filename you can get from however you specify the file for the component. If it is a variable, use that. If it is hardcoded, it will always be the same. I can't answer this bit for you without having your job.

This data needs to be written to your tFileOutputDelimited. It will be the first row.

 

The last subjob is where your data is added to the file. Simply link the tHashInput to the tHashOutput where you saved the data in memory above (the first subjob). Make sure the schema is that same as the tHashOutput. Then connect it to another copy of the tFileOutputDelimited. Make sure the schema of the tFileOutputDelimited is the same as the tHashInput. The ONLY change in the tFileOutputDelimited is that you must tick the "Append" tickbox.

 

If this is done correctly the first subjob will read the data into memory. The second subjob will write the row count and filename to the file. The third subjob will write the data stored in memory to the file after the row count and filename.

View solution in original post

6 Replies
Anonymous
Not applicable
Author

This needs a bit more of an explanation. You say you want a dynamic header, does that mean that the header will hold dynamic data or that you simply want it added after you have read the file? My assumption is that you simply want to take the filename and row count and add it to the top of the file. Is that correct? By the way, the sheet name of a CSV file viewed in Excel is the filename. If you post a screenshot of your job which gets you to this point (the file you've shown), I can point you in the right direction to achieve this if my assumption above is correct.

Anonymous
Not applicable
Author

Hi,

Yes you are correct i need to add the file name and count of row to be added at the top of my file. as of now my flow is like
tFileInputExcel->tMap->tFileOutputDelimted. please guide me

0683p000009M2d8.png

Anonymous
Not applicable
Author

Hi,
Can you explain me please
Anonymous
Not applicable
Author

OK, this is how I would do it.

You will need the tHashInput and tHashOutput components for this. If you do not have those available, you will need to find them. Take a look here for that...

 

https://community.talend.com/t5/Migration-Configuration-and/Where-are-the-tHashInput-and-tHashOutput...

 

Your job will look like below.

 

0683p000009M2Iy.png

The top subjob will be pretty much like yours is now, but you will replace the tFileOutputDelimited with a tHashOutput.

The next subjob uses a tFixedFlowInput with 2 columns. One for row count and one for file name. You can get the row count using a globalMap variable like this....

((Integer)globalMap.get("tFileInputExcel_1_NB_LINE"))

....check the name of your tFileInputExcel. Mine is called tFileInputExcel_1. Change the above variable key with the name of your component.

The filename you can get from however you specify the file for the component. If it is a variable, use that. If it is hardcoded, it will always be the same. I can't answer this bit for you without having your job.

This data needs to be written to your tFileOutputDelimited. It will be the first row.

 

The last subjob is where your data is added to the file. Simply link the tHashInput to the tHashOutput where you saved the data in memory above (the first subjob). Make sure the schema is that same as the tHashOutput. Then connect it to another copy of the tFileOutputDelimited. Make sure the schema of the tFileOutputDelimited is the same as the tHashInput. The ONLY change in the tFileOutputDelimited is that you must tick the "Append" tickbox.

 

If this is done correctly the first subjob will read the data into memory. The second subjob will write the row count and filename to the file. The third subjob will write the data stored in memory to the file after the row count and filename.

Anonymous
Not applicable
Author

Thanks alot it works now.

mpattnaik
Contributor
Contributor

What did happen here? I dont see the answer in the blog.