欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue+elementUI表格下载为excel

程序员文章站 2024-03-20 16:35:10
...

使用步骤

代码如下(示例):

安装插件
npm install --save xlsx file-saver
2:页面引入:
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
3.添加方法:
exportExcel () {
          var fixed = document.querySelector(".el-table__fixed");
          var excelTitle = "标题";
          var wb = XLSX.utils.table_to_book(document.querySelector("#table"));
          /* get binary string as output */
          var wbout = XLSX.write(wb, {
              bookType: "xlsx",
              bookSST: true,
              type: "array"
          });
          try {
              FileSaver.saveAs(
                  new Blob([wbout], { type: "application/octet-stream" }),
                  excelTitle + ".xlsx"
              );
          } catch (e) {
              if (typeof console !== "undefined") console.log(e, wbout);
          }
          return wbout;
        },
相关标签: Vue+Element UI