0

I want to import an xlsx file into my website and based it on this. However, whatever filename and path I put in, it gives me this error:

TypeError: Cannot read properties of undefined (reading 'F_OK')

The part in question looks like this:

const Excel = require('exceljs')
var workbook = new Excel.Workbook(); 
workbook.xlsx.readFile('spielplan.xlsx')

I have tried moving the file into different directories and using their paths, tried it from the directory itself, and have tried to give the absolute file path. Every time the same error mentioned above pops up.

What am I doing wrong?

hippiecat
  • 15
  • 3

2 Answers2

0

Can you share your folders structure?

And remember the root of your JS project is the current path from your shell, so make sure you are calling it from the right place.

Try to specify the relative path this way as well: workbook.xlsx.readFile('./spielplan.xlsx')

Jonas
  • 16
  • 2
0

attached image to describe dirtry this it worked for me,

    const fs = require('fs');
    const fullPath = fs.realpathSync('folder name in which file is/file.xlsx')
    let workbook = new Excel.Workbook();
    await workbook.xlsx.readFile(fullPath);
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the [help center](https://stackoverflow.com/help/how-to-answer). – Ethan Sep 24 '22 at 23:23