reactjs - 'ReferenceError: cptable is not defined' 运行 Jest 测试时,生成 excel 工作表的实际代码工作正常
问题描述
堆栈跟踪如下。
Test suite failed to run
ReferenceError: cptable is not defined
1 | import React, { Component } from 'react';
> 2 | import ReactExport from 'react-export-excel';
| ^
at cptable (node_modules/react-export-excel/node_modules/xlsx/xlsx.js:10:37)
at Object.<anonymous> (node_modules/react-export-excel/node_modules/xlsx/xlsx.js:6:1)
at Object.require (node_modules/react-export-excel/dist/ExcelPlugin/components/ExcelFile.js:19:13)
at Object.require (node_modules/react-export-excel/dist/index.js:7:18)
at Object.<anonymous> (components/CustomReport.jsx:2:1)
如果我跟踪跟踪,它会到达以下代码部分
在 cptable (node_modules/react-export-excel/node_modules/xlsx/xlsx.js:10:37)
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
我已经看到 github 问题,他们建议从组件代码中删除“use strict”,但我什至没有使用它。这是相关问题https://github.com/SheetJS/sheetjs/issues/324
解决方案
好吧,这个图书馆没有帮助,所以用另一个图书馆。
react-html-table-to-excel
在这里,您需要创建一个 html 表格,然后将该表格转换为 excel。我使用 CSS 隐藏了表格,所以我只能得到导出 excel 按钮。
推荐阅读
- python - 满足特定条件时为特定列的行添加值
- python - 仅从 numpy 中的分数幂计算实根
- nix - 如何找到 Nix 频道指向的提交?
- javascript - React.js 没有更新
- r - 如何从R中的数组中获取向量
- sonarqube - sonarqube 社区版是否提供任何类型的静态应用程序安全测试
- selenium-webdriver - 什么是用于全选和复制的 Selenium edgedriver Send Keys?
- r - 当它有零行和 n() 列时从列表中删除 tibble
- java - SCALA - java.lang.NoClassDefFoundError: org/scalactic/TripleEquals
- javascript - 如何在 Next.js 中使用 webpack 5 配置?