Node.js Papaparse Tutorial to Parse & Read Excel File & Export to CSV Using read-excel file Library
Jan 9, 2025
Official Website:
https://freemediatools.com
Show More Show Less View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video we will be looking at how
0:04
to actually convert your Microsoft Excel
0:06
file data to a CSV file so in nodejs
0:12
using Papa pars Library Papa par Library
0:15
it's a very popular package and Library
0:19
which allows you to convert files from
0:22
Microsoft Excel to CSV so we use this
0:25
module Papa PR and read Excel file these
0:28
two modules will use it together to
0:30
actually accomplish this task you see
0:32
basically let me show delete the output
0:35
file and show to you once again if I run
0:38
this node
0:39
jscript this is actually sample. excl
0:42
file and you can see this header rows
0:44
sample country segment country product
0:47
discount band these are the different
0:48
rows out there so this is Excel file and
0:51
now if I run this node J script what
0:54
will happen in the left hand side a file
0:56
will be created output. CSV you will
0:59
basically see all this data will be
1:01
converted into a CSV file so we will try
1:04
to show you guys step by step in writing
1:07
this code and first of all let me show
1:10
you the modules that we are using the
1:12
very first module that we are using just
1:14
go to npmjs.com and it's a nodejs
1:18
website to explore different modules
1:21
first is as I already told you which is
1:24
p a p a p a RS RSC popup parts power
1:30
Parts is a fast and Powerful CSV parser
1:34
which is uh almost 2 million downloads
1:36
weekly download it's a very popular
1:38
Library it has its own homepage as well
1:41
you can even use it in the browser as
1:43
well so it allows you to par your CSV
1:46
files and display them or read them
1:49
write them all these things you can
1:51
perform it we will use it inside our
1:53
nodejs application apart from that we
1:56
also are using read Excel file which
1:59
allows you to read your Excel
2:01
files read the
2:04
data also it has 102,000 weekly
2:07
downloads so after we install these two
2:11
modules guys we just need to include
2:13
them at the very
2:16
top so what I will do is that I will
2:19
simply paste
2:23
it so right here at the very top we will
2:26
include this module require it readex
2:30
file and we need the node module node
2:32
version we will require it then guys we
2:35
also need the papa par Library we'll
2:39
simply call this like
2:42
this so require it and also two built-in
2:46
modules file system to actually save and
2:49
read files and then
2:51
for uh the path module which is also a
2:55
built-in module so required so all the
2:58
modules we have required guys
3:00
now we just need to define the input
3:03
file and the output file so the Excel
3:06
file is present in the same directory so
3:08
what we can do path. resolve the path in
3:11
the current directory we have sample.
3:14
XLS and
3:16
same we will create path. resolve and
3:20
here we will create our output. CSV file
3:23
which will get created after you execute
3:25
the script so we have provided this
3:27
input file that is present and
3:30
provided our output file as
3:34
well so now we just need to Define a
3:36
simple function CSV sorry
3:40
Excel to
3:42
CSV file and here we need to pass our
3:46
Excel file and the CSV file as two
3:48
arguments so this will
3:51
be a Asing function just make sure you
3:54
put async keyword right
3:57
here and then we Define our function
4:00
Excel to CSV file and we pass our Excel
4:04
file and the CSV
4:12
file this is actually the function we
4:15
are defining guys first of all we need
4:17
to read the
4:18
data from Excel file for this purpose we
4:21
will be using
4:25
that read Excel file so we use a weit
4:29
key keyword right here a wait and then
4:31
we will use this uh read Excel
4:35
file you'll see we imported that and
4:38
this method allows you to pass our input
4:41
Excel file right here and then here we
4:43
need to convert them into CSV file so
4:47
here we will use the popup or Library it
4:49
contains this function which is pass
4:52
here we need to pass the rows whatever
4:54
rows that you got if you just console
4:56
log it you will simply see whenever you
4:59
read the Excel
5:01
file you will get this uh like this file
5:05
reader synchronize is not
5:12
defined so I think we are making some
5:16
kind of mistake right
5:21
here oh sorry before doing this guys we
5:25
do need to I forgot to tell you a wait
5:30
read Excel
5:32
file I think we did this read this Excel
5:36
we are reading it let me just paste the
5:38
full source code and show to
5:42
you so here what we are doing we reading
5:45
this you'll see that read Excel file /
5:50
node if I just console log it console
5:53
log
5:58
row we'll see see that so we are
6:00
actually getting this uh
6:02
array which contains the record right
6:05
here so it's a array here each array
6:07
containing records you'll see that so up
6:09
till now we have did this so after this
6:12
we need to convert this array to SC CSV
6:17
file so here we will actually use the
6:19
papa Parts library and here you'll
6:22
simply
6:25
use you can see we are using this
6:28
package and contain
6:30
a method called as
6:33
unpass and here we pass to rows right
6:36
here and then we need to re write this
6:39
file synchronize CSV file path and the
6:43
actual CSV file then we can simply print
6:46
out a simple message to the screen that
6:48
Excel data has been converted to CSV and
6:51
saved so if you just delete this output.
6:54
CSV let me change the file name to
6:58
Output 222
7:00
just to make sure and again run this
7:02
code so output 22. CSV will create guys
7:05
you will see that all the data has been
7:08
converted to comma separated value so
7:10
each value is separated by comma so
7:12
that's a CSV file so this is your Excel
7:14
file being converted successfully to a
7:16
CSV file guys so in this way you can use
7:19
the papa Parts library and the read
7:21
Excel file Library together to actually
7:23
do this process thank you very much for
7:25
watching this video please hit that like
7:27
button subscribe the channel and I will
7:29
be seeing you in the next video
#Educational Software
#Other
