超简单便捷的excel前端导出推荐(适用于多级表头)

 import * as XLSX from "xlsx";
 import FileSaver from 'file-saver'
 
 export(name){  // name 导出文件名
    try {
          const $e = this.$refs['xxx'].$el; // xxx 绑定的ref
          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'}),
            `${name}.xlsx`,
          )
       } catch (e) {
          console.error(e)
        }
 }

猜你喜欢

转载自blog.csdn.net/jw_xiaoming/article/details/128343671