需求:將el-table里面的數據導出為excel表格
解決方法: js-export-excel
步驟:
1、安裝
npm install js-export-excel
2、使用
const excelData = []; excelData.push({ 工作人員: "111", 指揮員: "222" }); const options = {}; options.fileName = "方案1"; //表格名稱 options.datas = [ { sheetData: excelData, // 表格數據 sheetName: "sheet", sheetFilter: ["工作人員", "指揮員"], // 表頭對應的sheetData的數據 sheetHeader: ["工作人員", "指揮員"], // 表頭名稱 columnWidths: ["8", "8"] // 列寬 } ]; const toExcel = new JsExportExcel(options); toExcel.saveExcel();
3、 Cannot read property 'encode_cell' of undefined 解決報錯
import XLSX from "xlsx";
window.XLSX = XLSX;
