VUE ElementUI 导出 excel 表格

  1. 步骤一 npm install --save xlsx file-saver 安装依赖
  2. 需要导出的页面 引入依赖
import XLSX from "xlsx";
import FileSaver from "file-saver";
  1. 写入对应事件
 // 导出事件
    exportExcel() {
      //  .table捕获excel的表格
      let wb = XLSX.utils.table_to_book(document.querySelector(".table"));
      let wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      let name = '想要导出的表格名字'
      try {
        FileSaver.saveAs(
          new Blob([wbout], { type: "application/octet-stream" }),
          name + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    }
发布了5 篇原创文章 · 获赞 14 · 访问量 412

猜你喜欢

转载自blog.csdn.net/qhyk519/article/details/105687504