How to add headers to the append to CSV in UiPath

Simple Question.

How can we add headers to a append to csv activity ? Like When I delete the file I want only for the first time to add headers and append data and then when I run the bot again it should only append data to the csv. Is this possible ?

Hi @Ishan_Shelke1 ,

Have you Checked the Append to CSV Activity ?

image

Yes @supermanPunch But I can’t find a option as such which can provide me headers.

@Ishan_Shelke1 This is Unclear, as to why the Deletion is happening.

For this, we can First Read the CSV file or Check if the CSV file is Present, meaning it has data, then if the File Exists and there is Data, there are already Headers added and we would need to Just Append the Data to the CSV file, if the CSV File is not present or Data is Empty, we could use the Write CSV Activity.

Is the above suggestion similar to what was required ?

If not, Could you please Explain a bit more in detail as where are you Stuck and if you are already receiving any errors for the methods you have tried.

Exactly this is what I want.

Hi @Ishan_Shelke1 ,
With the Build Data Table activity, you can create a table and write the headings. You can also use the Add Data Row or Add Data Column activity to print the data, including the headers, into your .csv file. There may be an alternative solution.

Can you just give me a sample workflow/steps to do this ?

@Ishan_Shelke1 You can check whether the CSV has rows in it . If it has rows then append data or write data in csv

Note : When trying to get rows and if there is no data in CSV it will throw an exception. so, we should handle this using try catch. You can check that in sample workflow attached below

Please find the below sample workflow for better understanding

CSV.zip (2.9 KB)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.