Тёмный

How to convert excel file into JSON object by using JavaScript 

Code Pro
Подписаться 2,7 тыс.
Просмотров 65 тыс.
50% 1

This video tells how to convert an excel file into a JSON object by using JavaScript. How to convert Excel File (xlsx, xls) to JSON with Javascript using XLSX (inbuilt functionality of sheetJS) library.
find source code here github.com/jayanthbabu123/exc...
find out more information on my blog here levelup.gitconnected.com/how-...
Initially, when I started working on this requirement, people suggested using any one of the backend libraries to read and convert the excel data into JSON objects. But it is difficult to send requests to the server every time. On the other hand, it was really easy to convert the excel file on the client into a JSON object by using pure JavaScript.
There is JavaScript plugin XSLX that can be used to read excel files as binary strings and to convert it into a JSON object.
Plugins Required: xlsx.full.min.js
Installation
Include the CDN link in the head tag of an HTML file like this:
Now, in the HTML body tag, we need to write an input tag with the type as a file and need to restrict the user to select only files with the extension of .xls or .xlsx. Paste the below code into your HTML body tag.
Now we need to add event listeners for both input and button elements for handling change in input and button click events.
In JavaScript we can add the event listeners to elements like this:
We can read the data in the excel file by using file reader as a binary string in JavaScript. Then we use XLSX which has a builtin facility of SheetJS to convert our binary string into a JSON object.
Now select the excel file and click on the convert button to display the JSON object in the browser. After that, we can use the JSON object for any manipulations and integrate the data into different UI layouts.

Опубликовано:

 

9 июн 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 98   
@richjg16
@richjg16 Год назад
After weeks of finding a simple solution, you gave it to me in 10 minutes. Thank you!
@CodePro-Jayanth
@CodePro-Jayanth Год назад
Thank you
@marie-elizeventer7080
@marie-elizeventer7080 2 года назад
Thank you very much for taking the time to make this video! The tutorial is very clear.
@codingworld1082
@codingworld1082 3 года назад
Great to see your video. Teaching not only the conversion but also the way of handling prototypes in console. Waiting for upcoming videos 🌸
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Will upload soon
@danielbrigida8523
@danielbrigida8523 3 года назад
This video helped me a lot! Thanks.
@nithinsamuel9995
@nithinsamuel9995 Год назад
Thank you for this video :) works great
@glxmind2835
@glxmind2835 3 года назад
dude, its really cool information, thanks!!
@tylersymons5776
@tylersymons5776 3 года назад
You have no idea how much this video saved my day xD
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Please subscribe to my channel
@user-nv7ub9dh9i
@user-nv7ub9dh9i Год назад
wow Thanks; for this awesome and helpful video,
@ravia8220
@ravia8220 3 года назад
Great video, it helped me a lot.
@igorstashok6294
@igorstashok6294 3 года назад
Thank you, bro!!! the best video on this topic
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Please subscribe to my channel
@confusedgeek277
@confusedgeek277 3 года назад
Nice work man really appreciates your work. Well done
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Please subscribe to my channel
@hakeemremila1688
@hakeemremila1688 3 года назад
Well done great job :)
@mrudulkolambe3307
@mrudulkolambe3307 2 года назад
Great Work!!!💯
@baturserter6540
@baturserter6540 2 года назад
Thank you very much.
@kuthub1989
@kuthub1989 3 года назад
Thank You, So Much. You have done a great job. keep doing.
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Please subscribe to my channel
@JustThink2000
@JustThink2000 Год назад
Thanks!
@anish92
@anish92 Год назад
Thank You so Much
@andresrodriguez3930
@andresrodriguez3930 3 года назад
You sir, are a legend.
@gopilakshman6508
@gopilakshman6508 2 года назад
Superb! :)
@linyerin
@linyerin 3 года назад
Good tutorial, thanks
@alinemat6384
@alinemat6384 2 года назад
Hi I`m trying to do exactly as you did, but there is a problem. the variable "selectedfile" is globaly defined. So the Eventlistener of the input object changes it only locally. The EventListener of the Button sees only an undefined variable !! Thats the problem with me. Now Could you please help me to fix it ? Thanks
@josinvill1571
@josinvill1571 2 года назад
Thank you so much sir.👍💯
@chewlujing4403
@chewlujing4403 4 года назад
thanks for sharing, it's very useful!
@CodePro-Jayanth
@CodePro-Jayanth 4 года назад
You are welcome!
@BabaAndBaby11
@BabaAndBaby11 Год назад
is it possible to call an api by using the json Object created here with an apikey and write down the data to the same excel sheet (in a new column) based upon the response returned from the api call?
@guapeousa
@guapeousa Год назад
Amazing tutorial! thank you! I have a question: How can I fetch the data from the new json data we just created? Or how can we save that json data into another file called "data.json" within our VS code? Thanks in advance for the help
@shakedbukai8079
@shakedbukai8079 3 года назад
really nice video and you explain perfectly is there a way to update to the web page when there is a change in the excel file? tried to do it with setInterval but it doesnt seem to work
@david2358
@david2358 3 года назад
Thank you!! It worked perfectly for me!! 👍👍
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Please subscribe to my channel
@david2358
@david2358 3 года назад
@Code Pro just subscribed 👍
@cristobalzapata4945
@cristobalzapata4945 Год назад
query, i have done a test putting the same code in js . It happens that if the column is empty, I don't get it, it returns the entire object. if any record of the column is empty. xexample: [{'x': null, 'y': "data"}], what it does is return me like this [{ 'y': "data"}]
@madison_master
@madison_master 2 года назад
Hello friend, do You know how can I pass the json to php to insert the data into sql? I'm trying but I cannot get to take out rowObject variable to send it to php
@Gyffet
@Gyffet 3 года назад
i got an error 'readAsBinaryString' on 'FileReader': parameter 1 is not of type 'Blob' how can i fix it?
@rontindoy5738
@rontindoy5738 3 года назад
this is great!!! thank you for showing us how to do it!
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
You are so welcome!
@khoroshoigra8388
@khoroshoigra8388 2 года назад
galing no
@patarebenezer
@patarebenezer Год назад
Cool
@chethanchethan4430
@chethanchethan4430 3 года назад
Can I have the link for your sample xlsx sheet ? To know how did you put up content in it
@asmitshrivastava7689
@asmitshrivastava7689 3 года назад
Thank you so much brother .
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Please subscribe to my channel
@levialviter2302
@levialviter2302 3 года назад
You're the shit. You've just saved me
@boddulasrikanth6047
@boddulasrikanth6047 3 года назад
great bro....do more useful videos
@SZOKE19940321
@SZOKE19940321 2 года назад
nice
@mauricehason
@mauricehason 2 года назад
Awesome, this saved me a lot of time. Is it possible to save the JSON file to the same location as the HTML file on the server instead of displaying it on the screen?
@KhangHoang-pr9kq
@KhangHoang-pr9kq 2 года назад
thank you. How can i start reading row 10 of the file, sir??
@RunySharklel
@RunySharklel 2 года назад
Maestro
@ChiranGB13
@ChiranGB13 3 года назад
Your code does not display excel multiple sheets data in document.getElementById("jsondata").innerHTML=JSON.stringify(rowObject,undefined,4); Is there a way to display multiple sheets data in tag. Also how to display it in HTML Table?
@prasheetpathak685
@prasheetpathak685 3 года назад
TypeError: Failed to execute 'readAsBinaryString' on 'FileReader': parameter 1 is not of type 'Blob'. Anyone suggest the solution for this error . Any help will be appreciated
@pranitchavan4549
@pranitchavan4549 11 месяцев назад
👏👏
@Racine14
@Racine14 2 года назад
Hello Sir, have you a tutorial about xlsx cdn ?
@arifdevcoding
@arifdevcoding 3 года назад
great bro!
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Thanks 🔥
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Please subscribe to my channel
@denissidorov7151
@denissidorov7151 3 года назад
if I want to download a few excel files?
@tienattr8227
@tienattr8227 2 года назад
how can i display like a list of table, sir?
@antonielresplandes
@antonielresplandes 3 года назад
How do I put a save file button?
@zkbn485
@zkbn485 3 года назад
thank you bro! but how can i insert a table[ ] ?
@EmmanuelNgwandu
@EmmanuelNgwandu 4 года назад
Thanks for sharing
@CodePro-Jayanth
@CodePro-Jayanth 4 года назад
Thanks for watching!
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Please subscribe to my channel
@dayroncarvajal4314
@dayroncarvajal4314 4 года назад
Muchas gracias hermano (y), me sirvio mucho
@dibyajyotimohanty9252
@dibyajyotimohanty9252 3 года назад
Can you plz make a video for nested json file into csv by using java
@peshotod
@peshotod 2 года назад
Very good tutorial.But there is one problem.JSON string cannot convert excel time from binary numbers to date and time format.The browser console can. JSON convert - "TransactionDate": 44595.43541666667, "EndTime": 44595.436111111114, Console.log convert - Ready To Batch,02/03/2022 10:27,02/03/2022 10:28,
@pouf2night
@pouf2night 3 года назад
This is very nice! First of all thank you. I just have one question about the code (I am a beginner ++ , so sorry if it's a silly one) what is the data array intended for? let data=[{ "name":"jayanth", "data":"scd", "abc":"sdef" }] I cannot figure it out and it does not appear in your explanation video. Thank you very much!
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Please subscribe to my channel
@ottoduke8942
@ottoduke8942 3 года назад
pro tip : watch series at flixzone. I've been using them for watching loads of movies lately.
@lochlanelliot3127
@lochlanelliot3127 3 года назад
@Otto Duke yea, I have been watching on Flixzone} for since november myself :D
@pallavi95028
@pallavi95028 3 года назад
IN IE 11 when uploaded the xls file it was not working any solution for that
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
I will check and let you know, can you tell me what exactly error is
@pallavi95028
@pallavi95028 3 года назад
@@CodePro-Jayanth Object doesn't support property or method 'attachShadow' this was the erro it is showing in the console
@nikhilt7617
@nikhilt7617 3 года назад
How to read an excel file which contains only headers in the first row? No other data except headers
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
When you read the data from excel you will get array of objects. Then you can use Object.keys to get the key of first object
@pbooth88
@pbooth88 2 года назад
useful video, but the sound quality is so very bad.
@hakeemremila1688
@hakeemremila1688 3 года назад
Can you share you Excel template please ?
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
You can upload any excel but it should have only one sheet
@gabrielaquino9391
@gabrielaquino9391 3 года назад
Hi Sir how about the excel with date format
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
medium.com/@jsomineni/change-the-code-like-this-when-creating-a-workbook-78f26dc14ec7
@gabrielaquino9391
@gabrielaquino9391 3 года назад
@@CodePro-Jayanth wow thank you :)
@ahmadyasir872
@ahmadyasir872 3 года назад
this is awesome! can you do this in angular? that would be outstanding!
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
Sure very soon,pls subscribe for updates
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-iT_l0l-SPDY.html
@quadral.shorts
@quadral.shorts 3 года назад
Hello sir! it says sheet_to_row_object_array does not exist.
@quadral.shorts
@quadral.shorts 3 года назад
lol, they changed it to sheet_to_json.Thanks good sir
@gpcubo4478
@gpcubo4478 Год назад
SOS ]UN CRACK
@zia44ful
@zia44ful 3 года назад
Very bad audio.
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
But the content is good, it's my first video Sorry for the inconvenience
@earlgroenewald9598
@earlgroenewald9598 3 года назад
This video was very helpful. Thanks a lot
@CodePro-Jayanth
@CodePro-Jayanth 3 года назад
If you like the video 📹, please subscribe to my channel 😊
Далее
Save Excel Table to a JSON File with Simple VBA Macro
20:00
Китайка Шрек всех Сожрал😂😆
00:20
🎸РОК-СТРИМ без ФАНЕРЫ🤘
3:12:10
Просмотров 1,4 млн
ТЫ С ДРУГОМ В ДЕТСТВЕ😂#shorts
01:00
5 JavaScript Concepts You HAVE TO KNOW
9:38
Просмотров 1,4 млн
Read JSON File into HTML with JavaScript Fetch API
6:27
Convert Excel to HTML Table using JavaScript
9:15
Просмотров 44 тыс.
Learn JSON in 10 Minutes
12:00
Просмотров 3,1 млн
How to Convert Excel Data to JSON Using VBA
25:59
Просмотров 29 тыс.
10 FREE Excel Add Ins to Boost Your Productivity
12:58
Просмотров 447 тыс.