直接調用:
//創(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);
}
指定字符集是因為office的Excel中文會出現(xiàn)亂碼子漩,而WPS的Excel不會(兼容微軟)。