Die vorgeschlagene Lösung nicht mit allen Browsern, aber ich fand einen Weg, es in allen Browsern zum Laufen zu bringen (Chrome, Firefox, IE11 und sogar Rand, ... weiß nicht, über IE9- 10, da ich keinen Zugang mehr zu ihnen habe).
Ich muss eine externe Bibliothek verwenden, um encoding.js zu verschlüsseln und es funktioniert erstaunlich gut mit Unicode (Ich kann meine Einhorn-Emoji in meinem CSV-Export in Excel sehen).
Also hier ist der Code
data = new TextEncoder('utf-16be').encode(csvContent);
// create a Blob object for the download
const blob = new Blob(['\uFEFF', data], {
type: 'text/csv;charset=utf-8';
});
// when using IE/Edge, then use different download call
if (typeof navigator.msSaveOrOpenBlob === 'function') {
navigator.msSaveOrOpenBlob(blob, filename);
} else {
// this trick will generate a temp <a /> tag that you can trigger a hidden click for it to start downloading
const link = document.createElement('a');
const csvUrl = URL.createObjectURL(blob);
link.textContent = 'download';
link.href = csvUrl;
link.setAttribute('download', filename);
// set the visibility hidden so there is no effect on your web-layout
link.style.visibility = 'hidden';
// this part will append the anchor tag and remove it after automatic click
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
und das ist es, es funktioniert in IE/Edge/Chrome/Firefox
Es könnte das Byte Order Mark sein. Hilft dieser Link? http://stackoverflow.com/questions/155097/microsoft-excel-mangles-diacritics-in-csv-files –
Ja ja ja! Hinzufügen des BOM-Präfixes funktioniert! –