import * as XLSX from 'xlsx'
import * as FileSaver from 'file-saver'
async handleExport() {
this.loading = true
this.oldtableData = this.tableData // 保留第一页数据到oldtableData
this.queryParams2.pageNum = 1
this.queryParams2.pageSize = this.total // 不分页查全部
await getTestData(this.addDateRange(this.queryParams2, this.dateRange)).then(response => {
this.tableData = response.rows
this.total = response.total
})
var wb = XLSX.utils.table_to_book(document.querySelector('#detail-table'), { raw: true })
var wbout = XLSX.write(wb, { bookType: 'xls', bookSST: true, type: 'array' })
try {
FileSaver.saveAs(
new Blob([wbout], { type: 'application/octet-stream' }),
'测试设备数据.xls'
)
} catch (e) {
if (typeof console !== 'undefined') console.log(e, wbout)
}
this.tableData = this.oldtableData // 导出完成 恢复成第一页数据
this.loading = false
return wbout
}
XLSX.utils.table_to_book 分页 导出所有数据
于 2024-01-12 11:46:16 首次发布