ng-csv
ng-csv copied to clipboard
Microsoft Excel 2010 doesn't render file with charset UTF-8
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).
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.
Thank you for the fix, it worked like expected. This should defiantly be included in the next release!
Might this be the reason for rendering öäå with similar artifacts? (Excel for Mac 2011)
i would think so. give it a shot.
+1
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 did you try to add add-bom="U+FEFF"
?
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.
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
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?
If I compress min version, encodeURIComponent(b)
display empty char, but the NOT min version, result is "%EF%BB%BF"
@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.
Update: Should have used uglify-js, not uglifyjs.
After using uglify-js it looks like this: c="\ufeff"