Tomáš Roj
Tomáš Roj

Reputation: 57

Cannot show diacritics in exported CSV file

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

Answers (1)

dev-cyprium
dev-cyprium

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:

  1. Open Excel
  2. Import the data using Data-->Import External Data --> Import Data
  3. Select the file type of "csv" and browse to your file
  4. In the import wizard change the File_Origin to "65001 UTF" (or choose correct language character identifier)
  5. Change the Delimiter to comma
  6. Select where to import to and Finish

Credit to original answer: Is it possible to force Excel recognize UTF-8 CSV files automatically?

Upvotes: 1

Related Questions