ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] # php # js https://github.com/SheetJS/sheetjs https://github.com/eligrey/FileSaver.js ## webpack ``` js /** * 导出excel * @param {dom} el 表格所在的dom * @param {String} title 标题 */ mixin_excel(el, title) { var wb = XLSX.utils.table_to_book(el,{raw:true}); //mytable为表格的id名 raw:true 把数字当成字符串 /* get binary string as output */ var wbout = XLSX.write(wb, { bookType: "xlsx", bookSST: true, type: "array" }); try { FileSaver.saveAs( new Blob([wbout], { type: "application/octet-stream" }), `${title}.xlsx` //导出的表名 ); } catch (e) { if (typeof console !== "undefined") console.log(e, wbout); } return wbout; }, ``` ## demo2 普通js ``` function exportExcel(el, title){ console.log('exportExcel',el) // el = $(el)[0] var wb = XLSX.utils.table_to_book(el,{raw:true}); //mytable为表格的id名 raw:true 把数字当成字符串 /* get binary string as output */ var wbout = XLSX.write(wb, { bookType: "xlsx", bookSST: false, type: "array" }); try { saveAs( new Blob([wbout], { type: "application/octet-stream" }), `${title}.xlsx` //导出的表名 ); } catch (e) { if (typeof console !== "undefined") console.log(e, wbout); } return wbout; } ```