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文件已被删除');
    });

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2021-06-29
  • 2021-10-01
  • 2021-05-24
猜你喜欢
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案