Advertisement

导出element ui表格合并表头的xlsx

阅读量:

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)
    }
      },

全部评论 (0)

还没有任何评论哟~