2

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.

Tibi
  • 439
  • 7
  • 15

1 Answers1

0

Your NodeJS version is old, you will need to upgrade its version.

See this discussion: https://github.com/ionic-team/ionic-cli/issues/2341

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

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • Sorry for the delayed answer.. I don't think that's it. I am running Node 12.13.0. Granted this is a bit older than 12.18.2 listed today on (https://nodejs.org), but not that much older. The github issue you mention states somewhere in the middle that it was working OK with node 7. – Tibi Jul 03 '20 at 19:27