Categories
JavaScript Answers

How to parse Excel (XLS) file in JavaScript?

Spread the love

To parse Excel (XLS) file in JavaScript, we use the read-excel-file package.

To install it, we run

npm i read-excel-file

Then we add an input with

<input type="file" id="input" />

Then we write

import readXlsxFile from "read-excel-file";

const input = document.getElementById("input");

input.addEventListener("change", async () => {
  const data = await readXlsxFile(input.files[0]);
});

to select the input with querySelector.

And then we add a change event listener with addEventListener.

We call readXlsxFile with the selected file to get a promise with the read Excel data as nested array.

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 *