import * as XLSX from "xlsx";
import FileSaver from 'file-saver'
export(name){ // name 导出文件名
try {
const $e = this.$refs['xxx'].$el; // xxx 绑定的ref
let $table = $e.querySelector('.el-table__fixed');
if(!$table) $table = $e;
const wb = XLSX.utils.table_to_book($table, {raw:true});
const wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST:true, type: 'array'});
FileSaver.saveAs(
new Blob([wbout],{type: 'application/octet-stream'}),
`${name}.xlsx`,
)
} catch (e) {
console.error(e)
}
}
超简单便捷的excel前端导出推荐(适用于多级表头)
于 2022-12-16 15:45:58 首次发布