In this short article and video, I will show you how to work with XLSX in Node.js.

In this short article and video, I will show you how to work with XLSX in Node.js.

In this video I will be showing the basics of using npm expecting that you already have Node.js installed 🔴 Subscribe for more

In this short article and video, I will show you how to work with XLSX in Node.js.

First, what is an XLSX file, it is a Microsoft Excel Open XML Spreadsheet created by Microsoft Excel. It stores the data as a compressed Zip file, which also contains a bunch of other files used to open the document. Now once we got that out of the way, let me show you how to work with it.

The first thing you will need to do is to install the XLSX package using NPM if you don't know what NPM is, then check this video out right here.

Installing the package XLSX from NPM
npm i xlsx

Importing dependencies
const XLSX = require("xlsx");

Reading the file into memory
const workbook = XLSX.readFile("file-example.xlsx");

Converting the XLSX to JSON so it's easier to work with
let worksheets = {};
for (const sheetName of workbook.SheetNames) {
    worksheets[sheetName] = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]);

This line is optional and only used for the debugging
console.log("json:\n", JSON.stringify(worksheets.Sheet1), "\n\n");

Modifying the XLSX file
    "First Name": "Bob",
    "Last Name": "Bob",
    "Gender": "Male",
    "Country": "United States",
    "Age": 35,
    "Date": "22/09/2020",
    "Id": 1600,
    "New Row": "test"

Updating the XLSX file
XLSX.utils.sheet_add_json(workbook.Sheets["Sheet1"], worksheets.Sheet1)
XLSX.writeFile(workbook, "file-example.xlsx");

Creating a new XLSX file
const newBook = XLSX.utils.book_new();
const newSheet = XLSX.utils.json_to_sheet(worksheets.Sheet1);
XLSX.utils.book_append_sheet(newBook, newSheet, "Sheet1");

If you would rather want a video version of this article:

xlsx node.js excel nodejs xlsx file

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Hire Node.JS Developers | Skenix Infotech

We are providing robust Node.JS Development Services with expert Node.js Developers. Get affordable Node.JS Web Development services from Skenix Infotech.

Top Node.js Development Companies and Expert NodeJS Developers

A thoroughly researched list of top NodeJS development companies with ratings & reviews to help hire the best Node.JS developers who provide development services and solutions across the world. List of Leading Node.js development Service Providers...

Hands on with Node.Js Streams | Examples & Approach

The practical implications of having Streams in Node.js are vast. Nodejs Streams are a great way to handle data chunks and uncomplicate development.

Downloading Files using Node.js

In this video I will be showing you how to download files off the internet using Node.js🔴 Subscribe for more