用希伯来语文本保存CSV文件

时间:2018-09-16 10:06:48

标签: javascript jquery csv encoding

当我保存CSV文件时,我得到了希伯来语的乱码,这是代码“我试图放入UTF-8,但仍然变得不合时宜。”

var data = [
       ['שם פרטי', 'programmer'],
       ['שם משפחה', 'bus driver'],
       ['כתובת', 'Reindeer Hunter']
    ];

    function download_csv() {
        var csv = 'Name, Title\n';
        data.forEach(function(row) {
                csv += row.join(',');
                csv += "\n";
        });

        console.log(csv);
        var hiddenElement = document.createElement('a');
        hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv);
        hiddenElement.target = '_blank';
        hiddenElement.download = 'people.csv';
        hiddenElement.click();
    }

0 个答案:

没有答案