npm install --save xlsx file-saver複製程式碼
需要的元件內引入
import FileSaver from "file-saver";import XLSX from "xlsx";複製程式碼
js
//匯出表格 exportExcel () { /* generate workbook object from table */ var wb = XLSX.utils.table_to_book(document.querySelector('#exportExcel')) /* get binary string as output */ var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' }) try { FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), 'OrderList.xlsx') } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) } return wbout }複製程式碼
exportExcel( 放入的是table 的DOM 節點 ) ,OrderList.xlsx 即為匯出表格的名字,可修改!
原文
https://blog.csdn.net/u010427666/article/details/79208145複製程式碼
目前只能匯出當前頁的資料,未完待續......