背景
vue3+element ui
el-table导出为excel时,以0开头的数据,其开头0被忽略,如002334导出到excel后变为了2334。
原因
导出为excel,自动给数据选用了excel的格式
解决方案
修改前的代码
import FileSaver from "file-saver";
import XLSX from "xlsx";
//定义导出Excell表格事件
ExportTableData: function () {
let wb = XLSX.utils.table_to_book(document.querySelector("#table1")); //从表生成工作簿对象 table1为需要导出的表格的id
console.log(wb);
let wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array",
}); //获取二进制字符串作为输出
console.log(wbout);
try {
FileSaver.saveAs(new Blob([wbout], { type: "application/octet-stream" })
"信息.xlsx"); //'信息.xlsx'为导出文件的名字
} catch (e) {
if (typeof console !== "undefined") console.log(e, wbout);
}
return wbout;
},