纯前端导出Excel,其他地方自行修改,这是例子,配合xlsx.full.min.js
下载地址:https://gitcode.com/TaoZY512/xlsx/blob/master/xlsx.full.min.js
function exportExcel(filename,sheetName, jsonArray ) {//展示的顺序,把data中对象的属性按照你想要的顺序排放就可以了const header = ["companyName", "strategy", "successDistribute", "successStrategy", "outage", "energize","percentage"];//展示的名称const header_zh = {companyName: "地市",strategy: "策略数量",successDistribute: "标工数量",successStrategy: "下发成功总数",outage: "断电数量",energize: "通电数量",percentage: "节能开启比例"};// 因为数据是有冗余的,但是实际上不需要显示那么多列,需要把多余的列进行剔除// 找到最后一列的编号let lastCol = XLSX.utils.encode_col(header.length - 1);// 找到最后一行的编号let lastRow = XLSX.utils.encode_row(jsonArray.length);const arrayWithHeader = [header_zh, ...jsonArray];const jsonWorkSheet = XLSX.utils.json_to_sheet(arrayWithHeader, {header: header,skipHeader: true});// 重新设置 单元格范围,剔除不需要的列jsonWorkSheet['!ref'] = "A1:" + lastCol + lastRow;//自定义列宽jsonWorkSheet["!cols"] = [{wpx: 250},{wpx: 80},{wpx: 80},{wpx: 80},{wpx: 80},{wpx: 80},{wpx: 80}];const workBook = {SheetNames: [sheetName],Sheets: {[sheetName]: jsonWorkSheet,}};XLSX.writeFile(workBook, filename);
}
exportExcel("节能监控","sheet1", [{},{},{}])
使用例子,很简单