【发布时间】: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