Categories
JavaScript Answers

How to read an Excel file using Node.js?

Spread the love

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

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

How to read an Excel file using Node.js?

To read an Excel file using Node.js, we can use the node-xlsx module.

To install it, we run

npm i node-xlsx

Then we can use it by writing

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

const obj1 = xlsx.parse(__dirname + '/myFile.xlsx');
const obj2 = xlsx.parse(fs.readFileSync(__dirname + '/myFile.xlsx'));

to call xlsx.parse with the path of the Excel file and assign the returned object to obj1.

Then we call xlsx.parse with a buffer returned from reading the Excel file with readFileSync and assign that to obj2.

Conclusion

To read an Excel file using Node.js, we can use the node-xlsx module.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *