Friday, December 14, 2012

When a Comma Isn’t

Stonefield Query has the ability to output reports to a CSV file. “CSV” is an abbreviation for “comma-separated values”, meaning there’s a comma between each value (which represents a field) in a row (which represents a record). Except when it’s supposed to be something else.

We recently had a customer in France report that when they output a report to CSV and then opened it in Microsoft Excel, numeric values didn’t come out right. I figured it was likely a regional setting, so I used the Control Panel Region and Language applet to change my setting to French (France) and voila (appropriate word choice, non?), was able to reproduce the problem. I thought perhaps the issue was that Excel didn’t like the fact that in France, a comma is used as a decimal separator, but changing a value like “45,25” to “45.25” didn’t fix the problem. Then I notice something I hadn’t noticed or heard of before: in the Customize Format dialog (click the Additional Settings button on the Formats tab of the Region and Language dialog), there’s a “list separator” setting. We in North America (and probably other places too) are used to having it be a comma, but for France, it’s a semi-colon.


Changing the CSV output to use a semi-colon instead of a comma for the separator fixed the problem. However, how to get the current value of the list separator? While VFP has functions to determine some of the user’s regional settings, such as SET(‘POINT’) (the character used for the decimal separator) and SET(‘SEPARATOR’) (the character used for the thousand separator), it doesn’t have one for this. Google turned up a few references to the Window API GetLocaleInfo function, but for some reason, that just gave me a blank rather than the expected comma or semi-colon. Fortunately, another site mentioned that it’s stored in the Windows Registry in the sList key of HKEY_CURRENT_USER\Control Panel\International.

So, now you can output a CSV file from Stonefield Query and while the “C” in “CSV” may not be accurate, the file is.

No comments: