I am trying to convert an excel document to CSV because I need to submit the final version as a CSV within the automation. However, I am having problems achieving this. Please assist. Is there something wrong with the logic of my code?
As you can see in the above screenshot, I have a datatable (DTvalue) that is initially expressed as an excel. Then, I try to use the DTvalue as an input to write a CSV file. However, it doesn’t work.
Your logic is mostly correct, but check these points:
• Ensure DTvalue has data (use DTvalue.Rows.Count)
• Verify your SQL query and DB connection
• Check the file path (try a simple path like C:\Temp\TestData.csv)
• Remove Append Range (not needed for CSV)
See the correct flow:
Execute Query → DTvalue → Write CSV
If DTvalue is empty, CSV won’t be created.
If solution work for you please mark as solution and happy automations with UiPath
Do you know why it won’t work? When I do it this way, is doesn’t add any information to the CSV file. But, if I do the same thing to an excel, as in the original post, it populates it with the correct information. I’m stuck trying to figure out why.
Hi @Sinenhlanhla_Shelembe
You can check the query is bringing value using this or it comes empty without value
DTvalue.Rows.Count.ToString
Also if your sql results contains null values sometimes it will throw error. You can replace the null values
If IsDBNull(row(“columnName”)) Then row(“columnName”) = “”
And also you can check the query is returning any special character characters like comma, linebreaks sometimes it’ll also cause the issue
@Sinenhlanhla_Shelembe From what you described, the logic is mostly fine. Since DTvalue is already getting populated correctly and it works when writing to Excel, the issue is likely not with the query, but with how the CSV activity is being used.
If your end goal is a CSV file,
keep the flow simple: Execute Query → store result in DTvalue → Write CSV
You do not need to append to Excel first
Please check below steps:
Confirm DTvalue has data Add a log or check: DTvalue IsNot Nothing AndAlso DTvalue.Rows.Count > 0
Use Write CSV instead of Append to CSV
Make sure the CSV file is not open If the file is open in Excel or Notepad, UiPath may not write to it properly.
The reason I created an excel first was to check if it was generating the correct outputs/ values. It was, but now the difficulty is creating a CSV.
I will check whether there are any special characters that may be causing the issues. Great suggestion. In case it does create any special values (commas particularly because there are), what should I do?
Yes, you’re correct. I tried this approach and surprisingly, on the first attempt it worked. But, since the first attempt, it now doesn’t populate the CSV file at all. I don’t know what the issue is because UiPath frequently presents this challenge where the same code can be run multiple times and get different outcomes every time. Your approach works, but now I am figuring out how to make it work every time.