【问题标题】:Not able to import xlsx无法导入 xlsx
【发布时间】:2022-06-14 16:28:27
【问题描述】:

我正在尝试添加一个函数来导出 xlsx。虽然我能够导出 CSV 和 pdf,但 xlsx 在动态导入时遇到问题

export const exportToXlsx = async (
  gridElement: ReactElement,
  fileName: string
) => {
  const [{ utils, writeFile }, { head, body, foot }] = await Promise.all([
    import('xlsx'),
    getGridContent(gridElement),
  ]);
  const wb = utils.book_new();
  const ws = utils.aoa_to_sheet([...head, ...body, ...foot]);
  utils.book_append_sheet(wb, ws, 'Sheet 1');
  writeFile(wb, fileName);
}

Cannot find module 'xlsx' or its corresponding type declarations.ts(2307)

上面是代码和错误

【问题讨论】:

    标签: reactjs typescript


    【解决方案1】:

    解决方案在官方文档中。这对我有用 https://www.npmjs.com/package/xlsx

    【讨论】:

      猜你喜欢
      • 2020-03-25
      • 2018-04-13
      • 2016-06-11
      • 1970-01-01
      • 2012-09-17
      • 1970-01-01
      • 2017-12-15
      • 1970-01-01
      • 2015-12-09
      相关资源
      最近更新 更多