vue 纯前端导出excel表格

1.安装 xlsx 库:使用 npm 或 yarn 安装 xlsx 库依赖。

npm install xlsx -- save

或

yarn add xslx

2.全局导入 xlsx 库 main.js

import * as XLSX from "xlsx";

Vue.prototype.XLSX = XLSX;

3.导出

  <el-button type="primary" @click="exportExcel()">导出</el-button>


   exportExcel() { 
      // 构造 workbook 对象
      let table = [
        ["姓名","性别","年龄"],["哈哈","男","18"],
      ];
      const ws = this.XLSX.utils.aoa_to_sheet(table);
      const wb = this.XLSX.utils.book_new();
      this.XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
      // 导出表格
      this.XLSX.writeFile(wb, "import.xlsx");
    },

猜你喜欢

转载自blog.csdn.net/future_1_/article/details/130618288