Node.js Tutorial to Export JSON File to Microsoft Excel XLSX File Using xlsx Library in Terminal
Jun 3, 2025
Get the full source code of application here:
https://codingshiksha.com/node/node-js-tutorial-to-export-json-file-to-microsoft-excel-xlsx-file-using-xlsx-library-in-terminal/
Watch My Visual Studio Code IDE Setup Video For Fonts,Themes & Extensions
https://youtu.be/Bon8Pm1gbX8
Hi Join the official discord server to resolve doubts here:
https://discord.gg/cRnjhk6nzW
Visit my Online Free Media Tool Website
https://freemediatools.com/
Buy Premium Scripts and Apps Here:
https://procodestore.com/
Show More Show Less View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
So in this video I will show you a
0:04
NodeJS script which will convert your
0:07
Excel file into uh JSON file Sorry it
0:11
will create a Microsoft Excel file from
0:14
a JSON file here So we have input JSON
0:18
file here inside my directory It has an
0:21
array of objects here Each object
0:23
representing one form of data So it has
0:26
various properties So I will convert
0:28
this JSON file into Excel file I will
0:31
write a script right here So as I run
0:34
the script right here you will see on
0:36
the left hand side as I run this
0:38
application it will create this Excel
0:40
file So it will automatically detect how
0:43
many records are present inside your
0:45
JSON file So five records found and it
0:47
converted the JSON to Excel
0:50
file So it created this Excel file right
0:53
here Excels Microsoft Excel file If I
0:56
open this now you will see uh all the
0:59
array of records in the JSON file has
1:02
been converted So we have the set of
1:04
columns we have set of
1:07
rows So in this easy way guys I will
1:10
show you a NodeJS script right here So
1:13
all the source code will be given in the
1:15
description of this video So first of
1:16
all you need to install this third party
1:19
module which is Excel S This is the
1:23
third party module that we are using
1:24
here Simply install this by this command
1:27
and after that we just need
1:30
to require this package XLS and we just
1:34
need to require
1:36
this and we also need the file system
1:39
module which is a built-in NodeJS module
1:42
After that we will read the JSON file
1:46
which using this function
1:49
JSON.parse It's a built-in function and
1:51
we will be reading the file here using
1:53
the file system module So read
1:55
file synchronize and here you will
1:58
specify your
2:01
uh uh JSON file here So the path here So
2:06
my path is present in the same directory
2:08
So I will just write output JSON and
2:11
that's all It will read this uh data
2:15
which is present in this file here It is
2:17
present if you see in my same
2:20
directory and after that it will return
2:23
the data and here we need to specify a
2:27
array So data array and we will
2:30
basically detect JSON data users or if
2:35
the data is not available in that
2:40
case we will simply say whatever is the
2:44
JSON data is there that's all after that
2:49
we basically construct the final data
2:53
and for this we use this uh
2:56
array and we detect if it is an array or
2:59
or not So is array and we specify the
3:02
data array and use the turnary operator
3:06
If it's an array here we need to specify
3:08
data array or data array like
3:15
this So after this step we basically log
3:19
the
3:20
data So we specify how many records are
3:23
present in the JSON file So we specify
3:27
the final data
3:28
dotlength So it will calculate the total
3:31
number of records and print it After
3:33
that we will create the worksheet of an
3:35
Excel file For creating the worksheet we
3:38
actually create a variable and there is
3:40
a function out this inside this module
3:43
xls utils
3:45
dot book
3:51
append_append
3:53
sheet And here you will specify the
3:56
workbook whichever workbook that you are
3:58
working on and then the
4:01
worksheet and here we specify the sheet
4:05
name So we create create this sheet name
4:08
right here which is sheet one inside
4:11
your workbook After that we actually
4:13
embed all the records So xls dot uh it
4:16
contains this function write file and
4:19
here we write this
4:21
workbook and the name name of the file
4:23
So let me say result
4:27
doxls and then we specify your
4:30
conversion is
4:36
complete that's all so now what I do I
4:40
delete this file here before running the
4:42
script just to cross check and as I run
4:46
this script right here you will see on
4:47
the left hand
4:49
side it is saying workbook is not
4:52
defined Uh sorry I think we haven't
4:55
defined the
4:56
variable
5:04
workbook Uh where is this
5:14
workbooks oh sorry we haven't defined
5:16
this variable
5:18
guys Sorry about it
5:21
We use this function which is
5:27
uh sorry we
5:31
basically what we
5:34
done we create the worksheet and the
5:41
workbook We create the worksheet by
5:44
using this uh method which is JSON to
5:47
sheet and we provide the data which is
5:50
final
5:51
data And then we create a new workbook
5:53
by using this function book new which is
5:56
contained Both these functions are of
5:58
this third party module XLS
6:01
utils book new After creating a new book
6:04
new workbook then we use this method xls
6:07
utils dot
6:09
book append sheet and we provide the
6:12
workbook the worksheet and the sheet
6:15
name So first of all we create the new
6:18
worksheet then we create the workbook
6:20
and then we append the data by using
6:22
this function So if I refresh you will
6:26
see on the left hand side data being
6:28
converted five records found and it
6:31
created this file here which is
6:34
result.xls and if I show you the data
6:37
has been successfully converted to an
6:39
excel file right here you will see it
6:41
automatically detected how many records
6:43
were present in the JSON file So a total
6:46
of five records were present and all
6:48
those records were converted into JS
6:50
Excel file So all the source code guys
6:53
will be given in the description and
6:54
also check out my website
6:56
freemediatools.com which contains
6:58
thousands of tools regarding audio video
7:00
and image
#Programming
#Software
