直接調(diào)用:
//創(chuàng)建文件并下載到本地 '\ufeff'指定字符集為utf-8
function downloadFile(fileName, content) {
var aTag = document.createElement('a');
var blob = new Blob(['\ufeff'+content],{ type: "text/csv" });
aTag.download = fileName;
aTag.href = URL.createObjectURL(blob);
aTag.click();
URL.revokeObjectURL(blob);
}
指定字符集是因?yàn)閛ffice的Excel中文會(huì)出現(xiàn)亂碼,而WPS的Excel不會(huì)(兼容微軟)。