vue3 excel下载 xlsx插件

1.安装插件:

npm install --save xlsx file-saver

 

2.页面中引入

  1. // 引入file插件
  2.  
    import FileSaver from "file-saver";
  3.  
    // 引入xlsx插件
  4.  
    import * as XLSX from "xlsx";
     
     
     
    3.事件

const export = () => {
//导出当前表格
var wb = XLSX.utils.table_to_book(document.querySelector("#tableId")); //表格id
var wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array",
});
try {
FileSaver.saveAs(
new Blob([wbout], { type: "application/octet-stream" }),
"order.xlsx"
); //文件名
} catch (e) {
if (typeof console !== "undefined") console.log(e, wbout);
}
return wbout;
},

posted @ 2022-07-07 16:28  elliot1004  阅读(1386)  评论(0编辑  收藏  举报