ng-csv icon indicating copy to clipboard operation
ng-csv copied to clipboard

Microsoft Excel 2010 doesn't render file with charset UTF-8

Open imjayson opened this issue 10 years ago • 11 comments

There is a bug in MS Excel where it doesn't honor the charset specified in the CSV file without a Byte Order Mark (BOM).

image

The fix is as such: var BOM = "%ef%bb%bf"; var DATA_URI_PREFIX = "data:text/csv;charset=utf-8," + BOM;

I'd love to submit a pull request but I am unable setup the dev env to run the existing tests.

imjayson avatar Aug 21 '14 02:08 imjayson

Thank you for the fix, it worked like expected. This should defiantly be included in the next release!

tvanro avatar Sep 19 '14 08:09 tvanro

Might this be the reason for rendering öäå with similar artifacts? (Excel for Mac 2011)

jkarttunen avatar Oct 07 '14 14:10 jkarttunen

i would think so. give it a shot.

imjayson avatar Oct 07 '14 14:10 imjayson

+1

alidavut avatar Oct 09 '14 07:10 alidavut

With ng-csv.min.js, a BOM is not prepended. It goes well with ng-csv.js. It looks like a problem related with uglifying.

eitetsujo avatar Mar 12 '15 01:03 eitetsujo

@eitetsujo did you try to add add-bom="U+FEFF"?

eirikb avatar Aug 27 '15 11:08 eirikb

It can not work for me. The file ng-csv.min.js is included as defined in package.json. And in my app, all vender js files are compressed as a single file. In this case, the BOM char '\ufeff' is replaced as empty char. If I add ng-csv.js by myself, the after compression, the BOM char is still right. So as most of the js libs do, the NOT min version file should be the main js.

Mavlarn avatar Jul 18 '16 11:07 Mavlarn

Another problem about the add-bom is, if I set add-bom="true" as that in example, the attribute true will be evaluated as string, but not boolean, so even add-bom="false" will be trated as enabling BOM.

Mavlarn avatar Jul 18 '16 11:07 Mavlarn

@Mavlarn Are you sure it's replaced with an empty char, and not the actual BOM char? E.g., if you run '\ufeff' in your console it will look empty, but it's there. You could perhaps even copy/paste this code into your console to see what I mean:

encodeURIComponent('')

That aside I don't understand why export to Excel isn't just a default UTF16 + delimiter, wouldn't that just always work?

eirikb avatar Jul 18 '16 11:07 eirikb

If I compress min version, encodeURIComponent(b) display empty char, but the NOT min version, result is "%EF%BB%BF"

Mavlarn avatar Jul 18 '16 11:07 Mavlarn

@Mavlarn You are correct. The minified file does have the correct char, but after running it through uglifyjs (version 2.4.10) the char is removed.

screenshot from 2016-07-18 13-51-41

Update: Should have used uglify-js, not uglifyjs. After using uglify-js it looks like this: c="\ufeff"

eirikb avatar Jul 18 '16 11:07 eirikb