安装依赖
npm install file-saver xlsx -S
然后在需要的页面中引入依赖包
import FileSaver from 'file-saver';
import XLSX from 'xlsx';
下面就是导出的方法
// 导出 handle_export() { var xlsxParam = { raw: true }; //转换成excel时,使用原始的格式,这样导出的时候数字过长不会变成科学计数法 let workbook = XLSX.utils.book_new(); let ws1 = XLSX.utils.table_to_sheet(document.querySelector('#table1'), xlsxParam); XLSX.utils.book_append_sheet(workbook, ws1, '已审核'); let ws2 = XLSX.utils.table_to_sheet(document.querySelector('#table2'), xlsxParam); XLSX.utils.book_append_sheet(workbook, ws2, '上传历史'); let ws3 = XLSX.utils.table_to_sheet(document.querySelector('#table3'), xlsxParam); XLSX.utils.book_append_sheet(workbook, ws3, '待审核'); let wbout = XLSX.write(workbook, { bookType: 'xlsx', bookSST: true, type: 'array' }); try { FileSaver.saveAs( new Blob([wbout], { type: 'application/octet-stream;charset=utf-8"' }), '审核列表.xlsx'); } catch (e) { if (typeof console !== 'undefined') console.log(e, wbOut); } return wbout; }
最新评论