npm install -S file-saver xlsx
npm install -S xlsx
import XLSX from "xlsx";
import FileSaver from "file-saver";
- raw:true 属性的意思是不自动把内容转换,不设置 true会出现100%转换为100
exportXls() {
let wb = XLSX.utils.table_to_book(document.querySelector("#out-table"),{raw:true});
let wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array",
});
try {
FileSaver.saveAs(
new Blob([wbout], { type: "application/octet-stream" }),
"导出模板" + new Date().valueOf() + ".xlsx"
);
} catch (e) {
console.log(e);
this.$message({
message: "操作失败",
type: "error",
});
}
},