Categories
JavaScript Answers

How to read Excel file using Node.js and JavaScript?

Spread the love

Sometimes, we want to read Excel file using Node.js and JavaScript

In this article, we’ll look at how to read Excel file using Node.js and JavaScript.

How to read Excel file using Node.js and JavaScript?

To read Excel file using Node.js and JavaScript, we use the node-xlsx package.

To install it, we run

npm install node-xlsx --save

Then we use it by writing

const xlsx = require("node-xlsx");

const obj = xlsx.parse(__dirname + "/myFile.xlsx");

to parse a file at the path with xlsx.parse.

We can parse a buffer with

const obj = xlsx.parse(fs.readFileSync(__dirname + "/myFile.xlsx"));

We read the file with readFileSync and then parse the returned buffer.

Conclusion

To read Excel file using Node.js and JavaScript, we use the node-xlsx package.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.