We are exporting a csv template that contains one row of headers looks like this:
HEADER 1, HEADER 2, HEADER 3
Then, the user fills in the contents and saves the csv. However, if you open it in Excel (which 99.99% of our users will be doing), save Chinese characters as content, and then open it back up, it comes back with ??
or __
. There is a fix that forces the user to save it as Unicode txt. However, we don't want to have to give people special instructions, and make it as easy as possible for them. This is currently our code that exports the template. However, it doesn't maintain the characters on re-save:
var blob = new Blob([ csvContent ],{encoding:"UTF-8",type:"text/plain;charset=UTF-8"});
var needsClick = true;
if (window.webkitURL) { // CHROME
var evt = document.createEvent("HTMLEvents");
evt.initEvent("click", null, null);
$("<a>", {
download : filename,
href : webkitURL.createObjectURL(blob)
}).get(0).dispatchEvent(evt);
} else {
if (document.createEvent) { // FIREFOX
var link = document.createElement("a");
link.setAttribute("href", encodeURI("data:text/csv;charset=utf-8,"
+ csvContent));
link.setAttribute("download", filename);
var e = document.createEvent('MouseEvents');
e.initEvent('click', true, true);
needsClick = link.dispatchEvent(e);
}
if (needsClick) { // IE
window.navigator.msSaveBlob(blob, filename);
}
}