我想获得一个可读的 xlsx 文件...我已经用库 SheetJS xlsx 编写了以下代码,但是我缺少一些东西,因为我无法下载一个可读的文件
const download = async (req, res) => {
let wb = XLSX.utils.book_new();
wb.Props = {
Title: 'Investments',
Subject: 'A test of subject',
Author: 'Finanze',
CreatedDate: new Date(),
};
wb.SheetNames.push('investments');
var ws_data = [
['S', 'h', 'e', 'e', 't', 'J', 'S'],
[1, 2, 3, 4, 5],
];
var ws = XLSX.utils.aoa_to_sheet(ws_data);
wb.Sheets['investments'] = ws;
res.setHeader(
'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
);
const wbout = XLSX.write(wb, {
bookType: 'xlsx',
type: 'binary',
});
res.send(wbout);
res.status(200).end();
};
router.get('/download', download);