html
<el-table id="table"></el-table>
js
import * as XLSX from 'xlsx'
/**
* 导出表格为xlsx文件
* @param { string } id 表格dom的id
*/
async function exportTable(id, fileName){
let wb = XLSX.utils.table_to_book(document.getElementById(id))
let wbout = XLSX.write(wb, {
bookType: 'xlsx',
bookSST: true,
type: 'array'
})
try{
XLSX.utils.book_append__sheet(wb, wbout)
XLSX.writeFile(wb, `${fileName}.xlsx`)
}catch(e){
console.log(e)
}
}
标签:xlsx,wb,表格,XLSX,导出,id,页面
From: https://www.cnblogs.com/shallow-dreamer/p/17539170.html