Node.js SheetJS Tutorial to Export CSV File to Excel File Using xlsx Module in Terminal
3 views
Jun 7, 2025
Buy the full source code of application here: 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/
View Video Transcript
0:00
welcome to this uh live stream so in
0:02
this live stream I will show you how to
0:04
convert your CSV file into Excel file in
0:09
NodeJS using a very famous library
0:11
called as sheetjs uh sheetjs is also
0:15
called as xls module if you go to
0:18
npmjs.com just search for this module
0:21
xls and the command is simple you simply
0:25
execute this command to install this
0:27
module so I've already installed it it's
0:30
also known as sheetjs an open-source uh
0:34
library for working with Excel files so
0:37
it's a very simple application which
0:39
converts your commaepparated value file
0:42
which is also called as CSV file so you
0:45
have this input dot CSV file and
0:48
basically it has this content right here
0:50
it has three columns
0:52
name age and country and then we have
0:55
two rows of data and now if I execute
0:58
the script here you will see it will
1:01
convert this CSV file to an Excel XLS
1:05
file right here which is an Excel file
1:07
so if I try to open this file it looks
1:09
something like this it converted this
1:12
CSV file into Excel file we have these
1:15
three columns name age and country and
1:18
then we have the two rows of data as
1:20
well so I will show you how to convert
1:23
this uh CSV file into Excel file in
1:25
NodeJS so now the code is pretty simple
1:30
so I will go step by step on how to
1:33
convert this so first of all just create
1:36
a simple index.js file and right here
1:39
you need to import the necessary modules
1:42
so we simply import the XLS module and
1:46
we simply require it like this and then
1:49
we also need the built-in path module as
1:54
well so we actually imported both these
1:57
modules right here you can see XLS
1:59
module and path module after that we
2:02
need to actually get the input CSV file
2:07
which is also present in the same
2:09
directory so path dot
2:12
join then similarly you'll be doing it
2:15
for the same thing for the output excel
2:17
file as well so here we provided all the
2:20
two files after that now we need to read
2:24
this CSV file for reading the CSV file
2:27
we use this sheet JS module so it
2:31
contains this
2:32
method which is read file and it
2:37
actually reads this input CSV file so we
2:40
simply pass the path here and the second
2:43
argument will be the type what type of
2:46
file is this so it said
2:48
file and the second property that we
2:51
need to pass here which is code page
2:53
which is equal to
2:55
65001 so in this first step here we
2:58
reading the CSV
3:01
file and then after that we just need to
3:05
get the sheet name so for getting the
3:07
sheet name we simply use workbook and it
3:11
contains this function which is sheet
3:13
names so here we put the
3:15
sheet we getting the first sheet and
3:19
then we actually the next step is to get
3:21
the actual sheet so to access that sheet
3:25
we simply use sheets and then we pass
3:28
the sheet name right
3:30
here so after doing this now we need to
3:33
read we need to write this to Excel file
3:36
for writing it for saving it to Excel
3:38
file we construct this new
3:42
workbook and then we again use this
3:45
utils dot and it contains this function
3:48
right here book new to actually create a
3:50
new book and then the next step is to
3:55
append this data so we have this
3:57
function right here which is book append
4:00
sheet and here we pass
4:04
this new workbook that we
4:07
created plus the sheet name and then you
4:10
can give any sheet name so I'm just
4:11
giving sheet one and then lastly we
4:14
simply save this by using the write file
4:20
method so this will save it as a new
4:23
excel file so here we provide new
4:25
workbook alongside with the
4:29
output so whatever that you have given
4:32
the name here output xls
4:35
path and then you can just give it a
4:38
notification message that your excel
4:40
file has
4:42
been created so that's all that we need
4:46
to do right here in this NodeJS script
4:49
so again if I delete this Excel file and
4:51
again run the script so you will see it
4:53
will convert this CSV file into Excel
4:56
file and you will get this file
5:00
created so if I try to open this file
5:04
you will see all the content of this CSV
5:06
file has been exported to Excel file so
5:09
if I add some more records right
5:21
here so as I added more records here
5:24
once again I execute this you will
5:32
see if I open the output excel file you
5:35
will see those records will be reflected
5:38
back so in this easy way NodeJS you can
5:40
export your CSV file into Excel file
5:43
very
5:44
easily and thank you very much for
5:46
watching this video
#Programming
#Software