// 导出 let exportToExcel = async () => { // 创建一个新的工作簿 const workbook = new ExcelJS.Workbook(); const worksheet = workbook.addWorksheet("Sheet 1"); // 在工作表中添加数据 const data = carStatNum.value; // 添加列的数据类型定义 worksheet.columns = [ { header: "进车辆", key: "countIn", width: 10 }, { header: "出车辆", key: "countOut", width: 10 }, { header: "时间", key: "hour", width: 10, style: { numFmt: "hh:mm:ss" } }, // 指定时间格式 { header: "保有量", key: "ownership", width: 10 } ]; data.forEach(row => { worksheet.addRow(row); }); // 将工作簿导出为Excel文件 const buffer = await workbook.xlsx.writeBuffer(); const blob = new Blob([buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); // 创建一个下载链接并模拟点击 const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = "车流时间段统计表.xlsx"; link.click(); };
// 导出 let exportToExcel = async () => { // 创建一个新的工作簿 const workbook = new ExcelJS.Workbook(); const worksheet = workbook.addWorksheet("Sheet 1");
// 在工作表中添加数据 const data = carStatNum.value; // 添加列的数据类型定义 worksheet.columns = [ { header: "进车辆", key: "countIn", width: 10 }, { header: "出车辆", key: "countOut", width: 10 }, { header: "时间", key: "hour", width: 10, style: { numFmt: "hh:mm:ss" } }, // 指定时间格式 { header: "保有量", key: "ownership", width: 10 } ]; data.forEach(row => { worksheet.addRow(row); });
// 将工作簿导出为Excel文件 const buffer = await workbook.xlsx.writeBuffer(); const blob = new Blob([buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
// 创建一个下载链接并模拟点击 const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = "车流时间段统计表.xlsx"; link.click(); }; 标签:execl,10,const,width,导出,header,link,key From: https://www.cnblogs.com/zhangxyang/p/18033847