VUE ElementUI 导出导入 excel 表格

导出

1. 步骤一 `npm install --save xlsx file-saver` 安装依赖

2. 需要导出的页面 引入依赖

import XLSX from "xlsx";

import FileSaver from "file-saver";

3. 写入对应事件


// 导出事件

    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;

    }

导入

你可能感兴趣的:(VUE ElementUI 导出导入 excel 表格)