在Electron应用程序中编辑Excel文件(Node.Js)



我有一个电子应用程序,我需要从Excel文件中读取数据并写回更改的数据。我还需要保留 Excel 文件的格式。

我正在使用的 Excel 文件是使用 Microsoft 365 商业版订阅版本 2005 内部版本 12827.20268 的 Excel 产品部分创建的。

我已经阅读了有关SO的建议,并决定尝试使用exceljs@4.0.1。问题是这个库在我尝试保存时给了我一个错误。

这是我使用的示例代码:

modifyExcel(): void {
// create a workbook variable
const workbook = new Excel.Workbook();
// read excel file from the path
workbook.xlsx.readFile(this.excelFile)
.then(() => {
// access the excel sheet
const worksheet = workbook.getWorksheet('My Sheet');
const rowValues = ['Case 1', 'case 1 file', '', 2, 3, 4, 5];
worksheet.addRow(rowValues);
workbook.xlsx.writeFile(this.excelFile)
.then(() => {
// eslint-disable-next-line no-console
console.log('saved to excel file successfully');
});
});
}

当我执行代码时,我得到一个异常:

exceljs.min.js?e8ae:3 Uncaught (in promise) TypeError: Cannot read property 'F_OK' of undefined
at eval (exceljs.min.js?e8ae:formatted:46534)
at new Promise (<anonymous>)
at Object.exists (exceljs.min.js?e8ae:formatted:46532)
at eval (exceljs.min.js?e8ae:formatted:56173)
at u (exceljs.min.js?e8ae:formatted:56173)
at Generator.eval [as _invoke] (exceljs.min.js?e8ae:formatted:56173)
at Generator.forEach.e.<computed> [as next] (exceljs.min.js?e8ae:formatted:56173)
at n (exceljs.min.js?e8ae:formatted:56173)
at s (exceljs.min.js?e8ae:formatted:56173)
at eval (exceljs.min.js?e8ae:formatted:56173)

我调试了代码,文件写入行上发生了异常。

workbook.xlsx.writeFile(this.excelFile)

有人见过这样的东西吗?如果是,您的解决方案是什么。

您的 NodeJS 版本较旧,您需要升级其版本。

请参阅此讨论:https://github.com/ionic-team/ionic-cli/issues/2341

和 https://github.com/hexojs/hexo-deployer-git/issues/126

最新更新