1.npm安装依赖
npm install xlsx fs
yarn安装依赖
yarn add xlsx
yarn add fs
表格添加属性:标签添加ref属性,用于获取该元素el;也可添加id属性获取
实现代码部分:
// 导入依赖 import * as XLSX from"xlsx/xlsx.mjs"; // 导出方法 exportBtn() { let table_elt = document.getElementById("exportTableRef") // Extract Data (create a workbook object from the table) let workbook = XLSX.utils.table_to_book(table_elt); // Process Data (add a new row) let ws = workbook.Sheets["Sheet1"]; XLSX.utils.sheet_add_aoa(ws, [], { origin: -1, }); // Package and Release Data (`writeFile` tries to write and save an XLSB file) XLSX.writeFile(workbook,"导出.xlsx"); }原创作者:吴小糖
创作时间:2023.11.13