// 下载xlsx表格
/**
*
* @param {* string } domId 要下载table的id
* @param {* string} name 要下载表格的name
*/
downExcel (domId, name) {
/* 从表生成工作簿对象 */
var wb = XLSX.utils.table_to_book(document.querySelector('#' + domId))
/* 获取二进制字符串作为输出 */
var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' })
try {
FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), name + '.xlsx')
} catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
return wbout
}
上面是js部分
html部分为
<el-button size="small" type="primary" @click="downExcel('表格的id', '下载时的表名称')">下载</el-button>
<el-table id="outTable">
...
...
</el-table>