故障排除
以下是一些常见错误及其解决方法。这并不全面。问题跟踪器 拥有丰富的信息和用户提供的示例。
¥Here are some common errors and their resolutions. This is not comprehensive. The issue tracker has a wealth of information and user-contributed examples.
其中许多错误已在新版本中得到修复!确保使用最新版本的库。一些旧端点已经过时。查看安装说明。
¥Many of these errors have been fixed in newer releases! Ensure that the latest version of the library is being used. Some legacy endpoints are out of date. Review the Installation instructions.
如果文档或问题跟踪器中未涵盖问题,或者文档中未讨论解决方案,我们将不胜感激你提供错误报告。
¥If issues are not covered in the docs or the issue tracker, or if a solution is not discussed in the documentation, we would appreciate a bug report.
特别感谢早期采用者和用户发现并分享了许多解决方法和解决方案!
¥Special thanks to the early adopters and users for discovering and sharing many workarounds and solutions!
安装问题
¥Installation Issues
NodeJS / NPM 超时
¥NodeJS / NPM Timeouts
错误包括
¥Errors include
WARN GET https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz error (ERR_SOCKET_TIMEOUT). Will retry in 10 seconds. 2 retries left.
SheetJS NodeJS 模块 可以在项目中作为 vendored。供应商完全将项目与 SheetJS CDN 分离。
¥The SheetJS NodeJS module can be vendored in projects. Vendoring completely decouples projects from the SheetJS CDN.
如果无法访问 SheetJS CDN,则可以通过 SheetJS 聊天 传递模块
¥If the SheetJS CDN is not accessible, modules can be delivered over the SheetJS Chat
错误
¥Errors
工作表中没有数据
¥No data in worksheets
参见问题 3273 了解更多上下文。这是一个网络浏览器错误,影响使用 V8 JavaScript 引擎的 Google Chrome、Microsoft Edge 和其他浏览器。
¥See issue 3273 for more context. This is a web browser bug affecting Google Chrome, Microsoft Edge, and other browsers that use the V8 JavaScript engine.
未捕获的类型错误:无法读取未定义的属性
¥Uncaught TypeError: Cannot read property of undefined
错误包括
¥Errors include
Uncaught TypeError: Cannot read property 'read' of undefined
Uncaught TypeError: Cannot read property 'writeFile' of undefined
Uncaught TypeError: Cannot read property 'utils' of undefined
根本原因是未定义的 XLSX
变量。这通常意味着库未正确加载。
¥The root cause is an undefined XLSX
variable. This usually means the library
was not properly loaded.
¥Review the Installation instructions.
如果在使用最新版本时出现错误,项目可能需要其他配置或加载策略。
¥If the error shows up while using the latest version, projects may require other configuration or loading strategies.
Upgrade Note (click to show)
Older versions of the library only shipped with CommonJS and standalone script. Webpack and other bundlers supported CommonJS dependencies with default import:
// old way
import XLSX from "xlsx";
Newer versions of the library ship with an ESM build. When upgrading, imports should be updated:
// new way
import * as XLSX from "xlsx";
import * as cptable from "xlsx/dist/cpexcel.full.mjs";
XLSX.set_cptable(cptable);
Newer releases support tree shaking, and special methods like writeFileXLSX
help reduce bundle size.
The bundler note explains in further detail.
"噢,啪!" 或 "糟糕,出现错误!"
¥"Aw Snap!" or "Oops, an error has occurred!"
浏览器有严格的内存限制,大型电子表格可能会超出限制。
¥Browsers have strict memory limits and large spreadsheets can exceed the limits.
对于大型工作表,请使用 密集的工作表:
¥For large worksheets, use dense worksheets:
var wb = XLSX.read(data, {dense: true}); // creates a dense-mode sheet
XLSX.writeFile(data, "large.xlsx"); // writeFile can handle dense-mode sheets
当必须处理非常大的文件时,请考虑使用 NodeJS 或其他服务器端技术在服务器中运行进程。
¥When processing very large files is a must, consider running processes in the server with NodeJS or some other server-side technology.
如果文件较小,请 向我们的问题跟踪器报告
¥If the files are small, please report to our issue tracker
历史上,稀疏工作表在小工作表中的性能更高。由于 2014 年 V8 中的错误 和 2017 年 V8 回归(为 Node 和 Chrome 提供支持的 JavaScript 引擎),大型稀疏工作表将使 Web 浏览器崩溃。
¥Sparse worksheets historically were more performant in small sheets. Due to a 2014 bug in V8 and a 2017 regression in V8 (the JavaScript engine powering Node and Chrome), large sparse worksheets will crash the web browser.