这是我的代码。它创建一个 xlsx 文件,该文件在 libreoffice 中打开,但在 excel-2007 中显示损坏
还 workbook.xlsx.write(response) 下载 .zip 文件
请帮忙。
var Excel = require("exceljs");
var express = require("express");
var bodyParser = require("body-parser");
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.all("/getExcel", function(req, res) {
var workbook = new Excel.Workbook();
var worksheet = workbook.addWorksheet("Discography");
worksheet.columns = [{ header: "Album", key: "album" }, { header: "Year", key: "year" }];
worksheet.addRow({ album: "Taylor Swift", year: 2006 });
worksheet.addRow(["Fearless", 2008]);
var rows = [["Speak Now", 2010], { album: "Red", year: 2012 }];
worksheet.addRows(rows);
worksheet.getCell("A6").value = "1989";
worksheet.getCell("B6").value = 2014;
workbook.xlsx.writeFile('taylor_swift.xlsx').then(fenter code hereunction() {
console.log("saved");
});
});