安装 xlsx
npm install --save xlsx
实现方法
toExcel(){
let workBook = XLSX.utils.table_to_book(document.getElementById('data'));
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
},
这里data 是table 的id,输出的文件名可以任意更改