How to convert excel file into JSON object by using JavaScript

preview_player
Показать описание
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.

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.
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.
Рекомендации по теме
Комментарии
Автор

After weeks of finding a simple solution, you gave it to me in 10 minutes. Thank you!

richjg
Автор

Thank you very much for taking the time to make this video! The tutorial is very clear.

marie-elizeventer
Автор

Great to see your video. Teaching not only the conversion but also the way of handling prototypes in console. Waiting for upcoming videos 🌸

codingworld
Автор

You have no idea how much this video saved my day xD

tylersymons
Автор

Thank you for this video :) works great <3

nithinsamuel
Автор

dude, its really cool information, thanks!!

glxmind
Автор

Nice work man really appreciates your work. Well done

confusedgeek
Автор

Thank you, bro!!! the best video on this topic

igorstashok
Автор

wow Thanks; for this awesome and helpful video,

nvubdhi
Автор

Thank You, So Much. You have done a great job. keep doing.

kuthub
Автор

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

shakedbukai
Автор

thanks for sharing, it's very useful!

chewlujing
Автор

this is great!!! thank you for showing us how to do it!

rontindoy
Автор

Thank you!! It worked perfectly for me!! 👍👍

david
Автор

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

guapeousa
Автор

You're the shit. You've just saved me

levialviter
Автор

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?

mauricehason
Автор

Can I have the link for your sample xlsx sheet ? To know how did you put up content in it

chethanchethan
Автор

Hello Sir, have you a tutorial about xlsx cdn ?

Racine
Автор

thank you. How can i start reading row 10 of the file, sir??

KhangHoang-prkq