bblog icon indicating copy to clipboard operation
bblog copied to clipboard

URL.createObjectURL(new Blob[...]) CSV 乱码问题

Open lishengzxc opened this issue 8 years ago • 0 comments
trafficstars

http://blog.csdn.net/leonzhouwei/article/details/8447643

原因是 Excel 以 ANSI 格式打开,不会做编码识别。

解决方法

function downloadCSV(fileName, content) {
    let a = document.createElement('a');
    let file = URL.createObjectURL((new Blob(['\uFEFF' + content], { type: 'text/csv;charset=utf-8' })));

    a.href = file;
    a.download = `${fileName}.csv`;
    a.click();
}

http://stackoverflow.com/questions/19492846/javascript-to-csv-export-encoding-issue

lishengzxc avatar Mar 10 '17 07:03 lishengzxc