Export to CSV

Hello.

I have a problem with exporting table data to CSV file.

In a windows I have a table, which shows data from PostgreSQL database. The last column (povprecni) is decimal number.


Then I have a button to export table data to CSV file.
When the export is done and I look at the CSV file, I see that numbers in last column doesn’t have comma as decimal separator, but dot:


Our locale is:


Is there anything that I can set or change in settings somewhere…? Because I need my decimal numbers in CSV file to have comma for decimal separator and dot for thousand separator.
I’ve tried to change setting in Windows control panel for Region and Language, but it seems that Ignition (or Java?) does not take, what’s in there. After every change I made, I restarted the PC, but no luck. I always get dot for decimal separator… :frowning:

1 Like

So this is indeed a bug and I’ve added it to our system. Unfortunately it’s not going to make it into the 7.5.6 release so I’m not sure exactly when it will be available. Probably a 7.5.7beta release sometime after 7.5.6 is officially made available.

Thank you. But what can I do until then?
I must export (automatically) some CSV’s every night, so that people can next day import them in Excel and evaluate them…

It might be a hackish solution, but since your data doesn’t contain periods in the first place maybe do something like this:

filename = "mydata.csv"

# capture the table and do the export
table = event.source.parent.getComponent("Table")
system.dataset.exportCSV(filename, 1, table.data)

# sanity check to make sure the file we exported was created
path = system.file.openFile(filename)
if path != None:
   contents = system.file.readFileAsString(path)
   fixed = contents.replace('.', ',') # simple replacement of periods with commas
   system.file.writeFile(filename, fixed, 0)

Writing a script will be your best option. You can take the approach offered up by @Greg.Buehler or as opposed to exporting it first just loop through the dataset and then create a list of your dataset rows, one entry per row. Then you could use the string.join(list) function of python to join the list into one large comma separated string that you could write to a file. Here is an ugly example of a possible loop:

[code]data = event.source.parent.getComponent(‘Table’).data
data1 = system.dataset.toPyDataSet(data)
new_data = []

for row in data1:
temp = []
for column in row:
temp.append(str(column))
new_data.append(",".join(temp))
my_string = “\n”.join(new_data)

print my_string[/code]

Hope this helps.

What about the “automatical” part of the question? Is there a way to do the export without prompting the user?

Yes, you can export the data without prompting the user. You just can’t use the function:system.dataset.exportCSVsince it is built-in to prompt the user. You need to do something like this:data = event.source.parent.getComponent("Table").data csv = system.dataset.toCSV(data, 1) system.file.writeFile("C:\\Path\\To\\File.csv", csv)

I just tried this in latest beta ‘7.5.7-beta4 (b1366) | 32-bit’ and I still get periods, not commas…

Which function did you use? The function that was fixed was the system.dataset.exportCSV(). If you used the system.dataset.toCSV() there still may be a locale issue with that function.

Now I’m confused. :confused:
I’m using system.dataset.exportCSV(). When I tried 3 days ago (on the same computer like today), it didn’t work (periods for decimal). When I tried now, it’s OK (commas for decimal)!? :scratch:
And I didn’t upgrade java or Ignition or anything…

OK, I’m not confused anymore… :slight_smile:
I tried again today.

I’m using this:

[code]import system, datetime
now = datetime.datetime.now()
timeStamp = str(now)
nameDateFile = now.strftime("%d%m%Y_%H%M%S")

filename = “%s_ph_egalizacija_povp.csv”%(nameDateFile)
#print filename

capture the table and do the export

table = event.source.parent.getComponent(“Table”)
path = system.dataset.exportCSV(filename, 1, table.data)
[/code]

and I get this in my CSV (period for decimal separator):

My regional settings are:


And my Ignition version is:


The same is when I use:

path = system.dataset.toCSV(table.data, 1, 0) print path

and I get:

Ok, I’ll submit another ticket for this. Your best option right now is to do it through scripting using one of the above examples until this gets resolved. Thanks for letting us know about this.

Ok, thanks.
And, I am using scripting for now and it’s working.

Hi,
I have the same problem, is it resolves?

Thanks