1.依据现有table导出

import XLSX,{WorkSheet} from 'xlsx'

let worksheet = XLSX.utils.table_to_sheet(document.getElementById('table'))
let workbook = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(workbook,worksheet,'数据报表1')
XLSX.writeFile(workbook,'数据报表2.xlsx')

2.依据data数据导出
https://zhuanlan.zhihu.com/p/268835049

3.封装一下

import XLSX from 'xlsx'

export function tableExport(tableId='table',sheetName='导出数据'){
  let worksheet = XLSX.utils.table_to_sheet(document.getElementById(tableId))
  let workbook = XLSX.utils.book_new()
  XLSX.utils.book_append_sheet(workbook,worksheet,sheetName)
  XLSX.writeFile(workbook,sheetName+'.xlsx')
}


作者 铁血 汉子 2022年7月1日
2024/11/21/04:54:22pm 2022/7/1/9:25:48
0 1106