1、引入
import FileSaver from ‘file-saver’
import XLSX from ‘xlsx’
2、导出
exportExcel(excelName) {
try {
const $e = this.$refs['listTable'].$el
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'
}),
`出勤表-月度汇总.xlsx`,
)
} catch (e) {
if (typeof console !== 'undefined') console.error(e)
}
},