I have an electron app where I need to read data from an Excel file and write back changed data. I also need to preserve the formatting of the Excel file.
The Excel file I am using is created with the Excel product part of the Microsoft 365 for Business subscription, version 2005, Build 12827.20268.
I have read recommendations on SO and decided to give a try to exceljs@4.0.1. The issue is that this library gives me an error when I try to save.
Here is the sample code I am using:
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');
});
});
}
When I execute the code I get an exception:
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)
I debugged the code and the exception occurs on the file writing line.
workbook.xlsx.writeFile(this.excelFile)
Anybody seen anything like this? If yes, what was your solution.