var fix = document.querySelector(".el-table__fixed");
var wb;
if (fix) {
wb = XLSX.utils.table_to_book(
document.querySelector(id).removeChild(fix),{raw:true}
);
document.querySelector(id).appendChild(fix);
} else {
wb = XLSX.utils.table_to_book(document.querySelector(id),{raw:true});
}
/* get binary string as output */
var wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array"
});
// get binary string as output
try {
FileSaver.saveAs(
new Blob([wbout], { type: "application/octet-stream" }),
title
);
} catch (e) {
if (typeof console !== "undefined") console.log(e, wbout);
}
return wbout;
组件头部导入
import XLSX from "xlsx";
import FileSaver from "file-saver";