前端页面上需要使用el-table
<el-button @click="exportExcel1()" type="primary" plain>导出</el-button>
<el-table :data="renyuan1" id="outExcel">//id就是下面方法导出数据所用的id
</el-table>
exportExcel,导出数据
exportExcel: function() {
let tables = document.querySelector("#outExcel") //根据id选取到要导出的表格
let table_book = this.$XLSX.utils.table_to_book(tables)
let table_write = this.$XLSX.write(table_book, {
bookType: "xlsx",
bookSST: true,
type: "array"
})
try {
this.$FileSaver.saveAs(new Blob([table_write], {
type: "application/octet-stream"
}), "导出名单命名.xlsx")
} catch (e) {
console.log(e, table_write)
}
return table_write
},