vue+elementUI表格下载为excel

1:准备工作:
安装插件
cnpm install --save xlsx file-saver
2:页面引入:
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
3:添加方法:
exportWageDetail(){
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
}
4:在table添加id
vue+elementUI表格下载为excel

导出之后,发现如果是身份证,会变成科学计数法,带着E,网上找半天,找到一个靠谱方法
![](https://s4.51cto.com/images/blog/202006/24/16ff9d3d0e0079543b03a9b1407b2184.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

添加这个之后,身份证会变成正常的字符串,学到了,感谢网上大佬。

猜你喜欢

转载自blog.51cto.com/butcher36/2506830