0

I have a copy of the sheetjs.js file and I would like to use it in my React TypeScript app.

I have entered a reference to the sheetjs in the HTML file found in public folder.

<script src="%PUBLIC_URL%/sheetjs.js"></script>

I have copied the file inside the public folder of the React application.

If I do the following:

React.useEffect(() => {
    let wb = new WorkBook();
}, []);

It throws this error:

Cannot find name 'WorkBook'.

How can I access sheetjs and its objects in component?

Tried this:

 const xlsx= XLSX.utils;

As stated in their documentation: const worksheet = XLSX.utils.json_to_sheet(rows);

It returns: Cannot find name 'XLSX'.

In the console it returns the following:

enter image description here

12
  • What's wrong with the current solution? Commented Nov 29, 2022 at 15:23
  • it throws: Cannot find name 'WorkBook'. Commented Nov 29, 2022 at 15:33
  • Did you import it? Where does Workbook come from? You're not providing enough code nor detail to help you. Commented Nov 29, 2022 at 15:35
  • Is this helpful? stackoverflow.com/questions/45658200/… - or this since its TS stackoverflow.com/questions/70482114/… Commented Nov 29, 2022 at 15:41
  • I have updated my post. I have added the file in the public folder of the react app. My question is, how can I reference this js file so I can use it in my component? I am not sure how to do that. That's why I am asking. Commented Nov 29, 2022 at 15:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.