How to you get this chrome API to download a CSV file that can be opened in Excel.
var csv = '123, 123, 美国'
chrome.downloads.download({
url: 'data:attachment/csv;charset=UTF-8,' + encodeURI(csv),
filename: name + '.csv',
saveAs: true
}
The root cause of the difficulty is that CSV file does not have any notion of encoding built in. And Excel when encounters a file with extension CSV it assumes it is single byte order and opens it that way. If you have double byte characters encoded in UTF-8 in your file Excel opens that file with garbage characters.
The answers in this question suggest that adding BOM to for UTF-8 will clue in Excel that this is a UTF-8 file.
Microsoft Excel mangles Diacritics in .csv files?
However no matter what we tried we could not get Excel to recognize the file Automatically. Using text import wizard or other text editors it works.
Here is a tool that lets you try various combinations. But none of the worked for us: http://jsfiddle.net/kimiliini/HM4rW/show/light/