首页 > 其他 > 详细

vue项目导出table数据为excel

时间:2022-05-27 20:45:02      阅读:4      评论:0      收藏:0      [点我收藏+]
import FileSaver from file-saver
import XLSX from xlsx
<el-button type="warning" @click="exportForm" icon="el-icon-download" >导出</el-button>
<el-table :data="listArr" border style="width: 99%" id="mainFrame" >
        <el-table-column prop="userName" label="姓名" align="center"></el-table-column>
        <el-table-column prop="logMonth" label="日期" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.logMonth | logMonth}}</span>
          </template>
        </el-table-column>
        
      </el-table>
methods方法:
exportForm() {
      var wb = XLSX.utils.table_to_book(document.querySelector(#mainFrame)) //  mainFrame  table的id
      var wbout = XLSX.write(wb, { bookType: xlsx, bookSST: true, type: array })
      try {
        FileSaver.saveAs(new Blob([wbout], { type: application/octet-stream }), 统计报表.xlsx)
      } catch (e) { if (typeof console !== undefined) console.log(e, wbout) }
      return wbout
    },

 

vue项目导出table数据为excel

原文:https://www.cnblogs.com/weiweiyeyu/p/15351756.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!