Reputation: 57
I wrote a js code that exported data into .csv table. My problem is that when I open the file Excel cannot show Czech diacritics like č or š. Anyone can help me?
function exportData(){
console.log("Started export to CSV.");
const rows = [
["Procesor" + " " + String(window.localStorage.getItem("CPU"))],
["RAM" + " " + String(window.localStorage.getItem("RAM"))],
["Displej" + " " + String(window.localStorage.getItem("display"))],
["Baterie" + " " + String(window.localStorage.getItem("battery"))],
["Grafická karta" + " " + String(window.localStorage.getItem("GPU"))],
];
let csvContent = "data:text/csv;charset=utf-8,"
+ rows.map(e => e.join(",")).join("\n");
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "parametry.csv");
document.body.appendChild(link); // Required for FF
link.click(); // This will download the data file named "my_data.csv".
}`
Upvotes: 1
Views: 562
Reputation: 768
On my mac, the UTF-8 CSV gets displayed properly, so this is a bug in Excel.
There's a similar question on SO that might be of interest to you, but here's a summary:
Credit to original answer: Is it possible to force Excel recognize UTF-8 CSV files automatically?
Upvotes: 1