asafdav / ng-csv

Simple directive that turns arrays and objects into downloadable CSV files
MIT License
572 stars 216 forks source link

European Excel wants Semicolon-Separated-Files. #28

Open jkarttunen opened 10 years ago

jkarttunen commented 10 years ago

Thanks for very helpful little project!

I just ran into Excel not opening the CSV file, bur displaying it as plain text. Turns out that european version of Excel want Comma-Separated-Files to be Semicolon-Separated-Files instead. 0_o

Maybe we can add as default or as an option 'sep=,' to the first line of the file to fix this thing.

See http://kb.paessler.com/en/topic/2293-i-have-trouble-opening-csv-files-with-microsoft-excel-is-there-a-quick-way-to-fix-this

asafdav commented 10 years ago

Hi, why can't you use the "field-separator" attribute ?

jkarttunen commented 10 years ago

Because then excel would not open the file properly (without import) with my US users. So I don't want to change the field separator, just make the excel understand what the field separator is, regardless of some stupid localization differences. What seems to fix excel default behavior when opening file is adding that separator to the top of the file with **sep=,***

asafdav commented 10 years ago

Your solution is Excel specific and I can't see any reference to it in the CSV spec, therefore we can't add just like that, it might break things for other users.

We can add an optional attribute for that, sounds good ?

andion commented 10 years ago

@jkarttunen You can always show a different ng-cvs tag for each user group. Just check their locale on an ng-if (or ng-switch) and set a different field-separator property for each one as noted by @asafdav

davorpeic commented 10 years ago

I just toped to this issue also, I'm try opening my csv in excel with spanish locale and it doesn't detect comma, I just hate M$ product in general :)

My workaround: I added sep=, to the first line because I'm exporting raw data and I don't mind users in 'non excel' apps see that first line.. it is not visible in excel thou..

pastafaria commented 10 years ago

Is there a way to export to an excel file (XLS or XLSX or otherwise) that has a similar interface to ng-csv?

asafdav commented 10 years ago

I plan to add XLSX support to this directive, any help from you guys would be highly appreciated !

On Thu, Jun 19, 2014 at 4:00 AM, pastafaria notifications@github.com wrote:

Is there a way to export to an excel file (XLS or XLSX or otherwise) that has a similar interface to ng-csv?

— Reply to this email directly or view it on GitHub https://github.com/asafdav/ng-csv/issues/28#issuecomment-46513062.

jkarttunen commented 10 years ago

@davorpeic How did you add sep=, to first line?

davorpeic commented 10 years ago

@jkarttunen well, you have several ways, first is avoid using built-in header and build your own, so you would create your JSON file in this order, first push is a sep=, then is header and then is everything else.

I'm working with CSV service all of my logic is behind and not on the front end as my JSON is generated by the app.

In my case, I'm encoding everything to base64 before sending it by email, so I'm adding sep=, just the moment before I send it, that way you can use built-in header creation as usual.

// Using $base64 service to encode
CSV.stringify(intervalJson, options).then(function(result){
    intervals = $base64.encode('sep=,\n' + result);
});

But it should work if you just put together those values without the encoding..

jkarttunen commented 10 years ago

Just used $scope.getTableHeader = function() { return ['sep=,']; };

and

     csv.unshift([["Name"], ["Description"], ["id"]]);
     return csv;

in $scope.getTable to get headers. Seems to work fine.

jkarttunen commented 10 years ago

@andion It would be flaky to deduce excel locale/installation from locale at web browser. And i would prefer my comma-separated columns separated by commas.

vstene commented 9 years ago

I had the same problem and solved this by adding a decimal-separator option; #77

jkarttunen commented 9 years ago

Great, thanks! I'll have this closed once i've viewed #77

gaia commented 9 years ago

Just to enrich the conversation: https://stackoverflow.com/questions/10140999/csv-with-comma-or-semicolon

AliMD commented 6 years ago

I have two problems with sep=,

  1. UTF8 encoding not detected by excel anymore! (even with DOM)
  2. Its only support in excel and not officially support in all CSV parser!

Any idea to solve utf8 issue ?!