Better Programming

Advice for programmers.

Follow publication

Write JSON Data Into an XLSX/Excel File in JavaScript

Convert your JSON into a .xlsx file and save it

Shubham Verma
Better Programming
Published in
2 min readJan 15, 2020
Convert JSON to XLSX file

Sometimes, we need to download a .xlsx file of JSON data.

So, in this article, I will show you how I can create a .xlsx file using JSON. To do this, let’s create our JSON first. I am keeping my JSON in a sample.json file and will import it when it’s required.

sample.json:

Github: sample.json

Now we have the JSON that we will use to create an XLSX file in our project directory. Now, we need to write our code to create the same.

So, to do this let’s create a file convert.js and paste the below code:

convert.js

Github: convert.js

Now we need to install the dependencies, to do this, go to the file location and run the below command:

npm install json2xls
Snapshot of “npm install json2xls”

Now that we have installed our dependencies, it’s time to run our app and create the sample.xlsx file in the same directory.

To do this, run the below command:

node convert.js

After doing this, you can see that the sample.xlsx file will be created in the same directory.

Snapshot of creating sample.xlsx

You can see that the sample.xlsx file has been created in the below GIF:

sample.xlsx created in the directory

Thanks for reading.

Shubham Verma
Shubham Verma

Written by Shubham Verma

A full-stack developer, In my free time, I write blogs and play guitar. I am both driven and self-motivated.

Responses (1)

Write a response