vue 导出为表格
时间:2020-03-19 00:08:04
收藏:0
阅读:77
1,终端运行
cnpm install --save xlsx file-saver
2,Script部分
import FileSaver from "file-saver"; import XLSX from "xlsx"; exportexcel() { //设置当前日期 let time = new Date(); let year = time.getFullYear(); let month = time.getMonth() + 1; let day = time.getDate(); let name = year + "" + month + "" + day; //console.log(name) //选择要导出的表格 var wb = XLSX.utils.table_to_book(document.querySelector(".table")); //console.log(wb) /* get binary string as output */ var wbout = XLSX.write(wb, { bookType: "xlsx", bookSST: true, type: "array" }); //console.log(wbout) try { // name+‘.xlsx‘表示导出的excel表格名字 FileSaver.saveAs( new Blob([wbout], { type: "application/octet-stream" }), name + ".xlsx" ); } catch (e) { if (typeof console !== "undefined") console.log(e, wbout); } return wbout; },
借鉴来源:https://blog.csdn.net/weixin_42429288/article/details/84140654
原文:https://www.cnblogs.com/xymaxbf/p/12520897.html
评论(0)