const xlsx = require(''xlsx)
const data = [{name: 'hello',age:1},{name: 'world',age:2}]
const jsonWorkSheet = xlsx.utils.json_to_sheet(data);
const workBook = {
SheetNames: [ 'Sheet0' ],
Sheets: {
Sheet0: jsonWorkSheet,
},
};
const filename = `report_${fecha.format(new Date(), 'YYYYMMDDhhmmss')}.xlsx`;
const filePath = path.resolve(this.app.config.baseDir, filename);
await xlsx.writeFile(workBook, filePath);
ctx.attachment(filename);
ctx.body = fs.createReadStream(filePath);
fs.unlink(filePath, err => {
if (err) throw err;
// console.log('excel文件已被删除');
});