Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Excel to JSON using Angularjs

I am trying to have a user upload an excel file from their computer then convert it to JSON. I am needing these files as JSON. I have it so they can upload a csv to JSON. Now I am wanting excel to JSON. Any advice or guidance on this would be appreciated. This needs to be done using angularJS. Thanks!

like image 468
Troy Reynolds Avatar asked Feb 18 '15 17:02

Troy Reynolds


People also ask

How do you convert excel to JSON using Javascript?

From this FileReader we can read the data in our excel file as a binary string. Then we use XLSX which an inbuilt facility of SheetJS js-xlsx to convert our binary string into a JSON object. To use XLSX you have to include the <script lang=”javascript” src=”dist/xlsx. full.

How do you convert excel file to JSON in react?

Hello everyone, in this post we will look at how to solve the React Convert Excel To Json problem in the programming language. import React, { useState } from "react"; import "./App. css"; import * as XLSX from "xlsx"; class ExcelToJson extends React. Component { constructor(props) { super(props); this.


2 Answers

Forget about file manipulation using AngulaJS. Angular is a front-end JS framework with no file manipulation support whatsoever. You need to have access to server where the file is stored and you will only get it with server side language.

EDIT:

Ok, I have learnt that you can use FileReader API or $parse Angular service to read file contents on the front-end, which is really cool.

Option A: Read this StackOverflow question and answer and follow the plnkr to see an example of FileReader API being used with Angular. Kudos to @MajoB for providing an excellent answer and code sample.

Option B: Check official Angular documentation to read about $parse service and check this fiddle to see it in action.

Unfortunately neither FileReader API nor $parse service can read Excel files. They can read .txt, .csv, .json, and even .html but not .xlsx

like image 85
codeepic Avatar answered Sep 29 '22 10:09

codeepic


Example code :

http://jsfiddle.net/d2atnbrt/3/

External library:

https://github.com/SheetJS/js-xls
like image 38
Krzysztof Raciniewski Avatar answered Sep 29 '22 08:09

Krzysztof Raciniewski