Hi! I have a problem writing a csv file into excel file because I get decimal numbers with both decimal separators (“,” and “.”)
My steps:
Reading csv file as a string (activity ‘Read text file’)
String is converted into datatable
Writing that DT into Excel
First picture shows csv column, and the second picture the same column written in excel.
Notice a difference in decimal separator within numbers with 3 decimal places. It needs to be with “,” as a decimal separator like in a first row!
This picture shows csv values in dt variable:
Csv file is a table with more than a hundred columns and It’s not an option to convert every single column with numbers into double format. It would take too long
Try this syntax. In the mean while can you share us sample input.
→ Read Text File
Output-> csvContent
→ Use below syntax in Assign
Assign -> dataTable = (From line In csvContent.Split(Environment.NewLine.ToCharArray())
Let adjustedLine = line.Replace(".", ",")
Select adjustedLine.Split(","c)).CopyToDataTable()
' Iterate through each column in the DataTable
For Each col As DataColumn In dt.Columns
' Check if the column is of type Double (or any numeric type)
If col.DataType Is GetType(Double) Then
' Iterate through each row in the DataTable
For Each row As DataRow In dt.Rows
' Perform the replacement operation for the specific column in each row
row(col) = row(col).ToString().Replace(".", ",")
Next
End If
Next
Can you elaborate? Your input file has 2 type decimal separator (“,” and “.”), right?
The above expression replace dot with comma in “Value” column to unify single decimal separator “,” Isn’t this same as your intent?
As my csv file contains more than a hundred columns, some of them have the same name. So, when I’m generating a datatable I don’t use option ‘Use headers’ because it gives me an error that I have duplicate columns. So, my first row is with the actually column names. I think its the reason why robot can not detect column type.
After I generate a data table, I use first row values with column indexes to rename columns in the whole DT. But then I don’t know how to check wether is column a type ‘double’.
Because if there are comma and 3digits, the comma is recognized as thousand separator in invariant culture. So it’s recognized some number larger than 1000. As thousand separator is dot in your locale ,it’s displayed finally.