為啥前端導出不在贅述了
第一步:安裝xlsx
npm install xlsx
第二步:創建js文件html2excel
import * as XLSX from 'xlsx';const htmlToExcel = {getExcel(dom, title = 'temp'){var excelTitle = title;// const XLSX = require("xlsx");var wb = XLSX.utils.table_to_book(document.querySelector(dom));try {XLSX.writeFile(wb, excelTitle + '.xlsx');} catch (e) {if (typeof console !== 'undefined') {console.log(e);alert('導出失敗!');// console.log(e, wbout);}}// return wbout;},
};export default htmlToExcel;
第三步:htmlToExcel.getExcel('#selectTable','導出的自定義標題')導出Excel文件
html2excel.getExcel("#table", "商品價格數據");
總結:適用于數據量不大的表格