无法在导出的CSV文件中显示变音符号

时间:2019-11-26 18:46:33

标签: javascript excel

我写了一个js代码,将数据导出到.csv表中。我的问题是,当我打开文件时,Excel无法显示č或š这样的捷克变音符号。有人可以帮助我吗?

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".
            }`

1 个答案:

答案 0 :(得分:1)

在我的Mac上,UTF-8 CSV可以正确显示,因此这是Excel中的错误。

您可能会对SO有类似的问题,但这是一个摘要:

  1. 打开Excel
  2. 使用数据导入数据->导入外部数据->导入数据
  3. 选择“ csv”文件类型并浏览到您的文件
  4. 在导入向导中,将File_Origin更改为“ 65001 UTF”(或选择正确的语言字符标识符)
  5. 将定界符更改为逗号
  6. 选择要导入的位置并完成

相信原始答案:Is it possible to force Excel recognize UTF-8 CSV files automatically?