我有一个对象数组,如下所示:
[
{ "FirstName": "John",
"LastName": "Parker",
"Age": "23",
"Cat": "23g",
"SOP": "Active"
},
{ "FirstName": "Rose",
"LastName": "Jackson",
"Age": "44",
"Cat": "44g",
"SOP": "InActive"
}
]
我正在使用excel4node创建对象的数据并将其写入 excel
async generateExclReport(req, res) {
try {
var wb = new xl.Workbook();
// Add Worksheets to the workbook
var ws = wb.addWorksheet('Report');
ws.cell(1, 1).string('FirstName');
ws.cell(1, 2).string('LastName');
ws.cell(1, 3).string('Age');
ws.cell(1, 4).string('Cat');
ws.cell(1, 5).string('SOP');
var fileName = "Report" + Date.now().toString() + '.xlsx';
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
res.setHeader("Content-Disposition", "attachment; filename=" + fileName);
wb.write(fileName, res);
} catch (err) {
this.handleError(res, err);
}
}
我可以在 excel 中打印标题并下载,但是如何在 excel 中打印对象的数据?
非常感谢任何帮助。