石广澎
2023-11-29 20913c80c3f5fc8e533cb92b90e6f20bcd68e032
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import FileSaver from 'file-saver';
import * as XLSX from 'xlsx'
 
export default {
  // 导出Excel表格
  exportExcel(excelName, tableName) {
    //excelName表示生成excel的文件名     tableName表示表格的id
    let tables = document.querySelector(tableName).cloneNode(true) // 重点
    tables.removeChild(tables.querySelector(".el-table__fixed")) // 重点
    var wb = XLSX.utils.table_to_book(tables,{raw:true})
    var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' })
    try {
      FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), excelName)
    } catch (e) {
      if (typeof console !== 'undefined') console.log(e, wbout)
    }
    return wbout
  }
}