Convert JSON into Excel sheet in Node.js || Project

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey guys welcome back once again in this video i am going to show you how to convert json into excel sheet okay so basically we will create a note project and there we will have a json and we will try to convert that json into excel sheet so let's get started for that let's go to your file okay so where you want to create a project so do right click and create a folder and let's call it as json to excel so now let's open this folder into vs code so here vs code okay so new folder and here i will select json to excel and i opened here okay so now let's open terminal so if you don't know shortcut here you have to select this terminal and click on new terminal so you will get a terminal here and now we have to create a note project so for that here we will run a command so npm init and here we will pass this flag as a yes okay so this is gonna to create a basic note project with packet.json so as you can see here we have here packet.json so now we need to install a package to this project and that is called xlsx okay so for that here npm install here and xlsx okay so let's install this and here let's create a new file so new file and we will call it as so index.js now here let's create a json so for that a student and this is going to be array here object so here we have two object so now let's import the slx const here xlsx equal to require slx okay so now here what we will do is we will write a function okay so i will call it as here convert json to excel okay and this is going to be our error function and here to call this function i will call it here okay so first of all here we need to create a worksheet into the excel sheet so here const walk sheet and this worksheet can be created by using utils function of slsx okay xlsx dot here utils dot and here we have one function json to see it so basically this is gonna to take a json object and will convert into the sheet here so here we will pass our json and we have our json in student object so students so now we have created the worksheet now we need to create a workbook so for that here workbook and here similar way we have another one function and that is called book new okay so this is gonna to create a fresh workbook okay so now here we have worksheet and we have workbook and now our task is to combine both of them okay so for that here we have another one method book append sheet that means we will append our sheet into the book so for that here x selects okay dot utils dot book append sheet okay and this is gonna to take three parameter first parameter is work book okay and second parameter is worksheet and third parameter is seat name okay so whatever the name you want to give to your seat so here i will call it as students only so now we have attached our seat to the book so now we have to create a buffer so buffer is gonna to help once we have large amount of data so for that here generate bob for okay and here xlx dot right okay and here i need to pass our book so work book comma and here in second parameter i have to pass a object and here i need to pass your book type okay so the book type is gonna to be our x l s x okay and here type i will pass as a buffer binary string so for that here i will write slx dot write okay and here i need to pass workbook only and the book type here is going to be same as before xlx but type here is gonna to be this time binary so now we have converted into the binary string now we need to download that file so here slx dot write file okay and here we have to pass to parameter first parameter as a data so we have data in our workbook so here workbook and second parameter we have to pass our file name okay so i will call it as students so student data dot x l s x okay so now save it and here we have created this worksheet after that we have created a phrase workbook and we have appended our seat to the book okay and we have provided name as a student after that we have generated buffer and it is going to help me a lot once we have large amount of data okay after that we have converted into the binary string and at last here we are writing into the file and we will get downloaded this so now save it and here node index dot js okay to execute this file we have to type node index.js so now hit enter and here as you can see we got this file students data so now let's come here and open this a student's data so here as you can see we have name email and age okay so now let's add another one field here to our excel sheet so let's call it as gender and gender is mail okay so gender is male here now save it and let's execute again okay so now we are getting this error because already this file exists okay so for that here as of now let's delete this file from here oh let's close from here okay so now delete this one and let's execute again here okay so now students data got created again and here i clicked and now as you can see we have this gender field and we have this mail option okay guys so in this video we have seen how to convert a json into the excel sheet so you can get the download link of this code in description of this video if you like this video do like share and subscribe see you in next video thanks for watching you
Info
Channel: Codenemy
Views: 24,825
Rating: undefined out of 5
Keywords: codenemy, Convert json to excel, node js, react, project, convert, json, into, excel, xlsx, google sheets, how to, rest api, node js tutorial, node js tutorial for beginners, node js crash course, convert json to csv, Convert json to table, excel to json
Id: vbzAnI1hvQU
Channel Id: undefined
Length: 9min 39sec (579 seconds)
Published: Thu Aug 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.