How to Convert Excel file into JSON by using Angular | JavaScript | JSON

preview_player
Показать описание
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 a JavaScript plugin XSLX that can be used to read excel files as binary strings and to convert them into JSON objects.

We can read the data in the excel file by using a file reader as a binary string in JavaScript. Then we use XLSX which has a built-in facility of SheetJS to convert our binary string into a JSON object.
Рекомендации по теме
Комментарии
Автор

woah amazing friend, this works for me 100%, I think just add how to drop a file(because for me didn't work or maybe it's just adding something in the html) and it will be the most complete video about this topic thanks

Oneslothj
Автор

readAsBinaryString is deprecated ⚠️ please tell what can be the alternative to use any method

soumyajeetbai
Автор

The expiry date is not showing the correct format. How can we resolve this date and time format issue?

MrChakri
Автор

How to validate the values after reading? Suppose in your excel file you are having InsVal - its value should be number but what if user enter a-z characters ? How to handle

manojradharapu
Автор

why u dont have any error in "let binaryData = event.target.result" that the object is possibly null

alradiation
Автор

Bro How to use in Require js. In Require Js it's showing error.

vishnuvirat
Автор

can you share the how to convert the excel to json data with using the react please tel me

kiranbegari
Автор

Can you please tell me how to access the JSON object out of that method. Even though I assign it to global variable, but it is not accessible after the method.. please help me here

vamshichekka
Автор

Thanks for sharing the technique, it's easy to understand and descriptive.

GauravSharma-grbs
Автор

Do you know if there is a way to convert the Json to a typed object. I tried sheet_to_json<MyModel>, but the json is still just an object and it doesn't know that it is MyModel. It knows it from an intellisense standpoint because typescript is loosely coupled. However, when I try to validate the model using class-validator, it doesn't validate anything because it doesn't know the actual model to look at. I'm trying to do it as generically as possible so I can reuse the code. In other words, I don't want to use Object.assign(MyModel, jsonObject) in order to get it to work because I need MyModel to be generic.

BillMoman
Автор

Nice job man, you have another subscriber! Would you mind showing how to generate the converted json file to folder on the project and not in the dom

randallerasmus
Автор

Hi bro u can share ur project plz? nice tutorial

MYPECOVMedia
Автор

Will it work for multiple sheets as well ?

kalaivanik