vue+elementUI 表格下载为excel
程序员文章站
2024-03-20 16:31:16
...
vue + elementUI 表格下载为excel
1. 安装插件:
npm install --save xlsx file-saver
2. 引入插件:
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
3. 添加导出按钮
<el-button type="primary" plain size="mini" @click="exportOrderData()">导出</el-button>
4. 添加方法:
exportOrderData() {
var xlsxParam = { raw: true };
var wb = XLSX.utils.table_to_book(document.querySelector('#out-table'),xlsxParam);
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
},
5. 设置 id="out-table"
在需要导出为 excel 的表格上添加 id
<el-table
:data="dataList"
border
v-loading="dataListLoading"
@selection-change="selectionChangeHandle"
id="out-table"
>
</el-table>
参考:
[1] vue+elementUI表格下载为excel
上一篇: netty实现http服务器