使用Angularjs将Excel转换为JSON

时间:2022-09-15 11:44:42

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!

我试图让用户从他们的计算机上传excel文件,然后将其转换为JSON。我需要这些文件作为JSON。我有它,所以他们可以上传一个csv到JSON。现在我想要excel到JSON。对此有任何建议或指导将不胜感激。这需要使用angularJS来完成。谢谢!

2 个解决方案

#1


3  

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.

忘掉使用AngulaJS的文件操作。 Angular是一个前端JS框架,没有任何文件操作支持。您需要访问存储文件的服务器,并且只能使用服务器端语言。

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.

好的,我已经了解到你可以使用FileReader API或$解析Angular服务来读取前端的文件内容,这真的很酷。

Option A: Read this * 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.

选项A:阅读此*问题并回答并按照plnkr查看与Angular一起使用的FileReader API的示例。感谢@MajoB提供了出色的答案和代码示例。

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

选项B:检查官方Angular文档以阅读有关$ parse服务的信息并检查这个小提琴以查看它的实际效果。

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

不幸的是,FileReader API和$ parse服务都无法读取Excel文件。他们可以读取.txt,.csv,.json甚至.html,但不能读取.xlsx

#2


1  

Example code :

示例代码:

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

External library:

外部图书馆:

https://github.com/SheetJS/js-xls

#1


3  

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.

忘掉使用AngulaJS的文件操作。 Angular是一个前端JS框架,没有任何文件操作支持。您需要访问存储文件的服务器,并且只能使用服务器端语言。

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.

好的,我已经了解到你可以使用FileReader API或$解析Angular服务来读取前端的文件内容,这真的很酷。

Option A: Read this * 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.

选项A:阅读此*问题并回答并按照plnkr查看与Angular一起使用的FileReader API的示例。感谢@MajoB提供了出色的答案和代码示例。

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

选项B:检查官方Angular文档以阅读有关$ parse服务的信息并检查这个小提琴以查看它的实际效果。

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

不幸的是,FileReader API和$ parse服务都无法读取Excel文件。他们可以读取.txt,.csv,.json甚至.html,但不能读取.xlsx

#2


1  

Example code :

示例代码:

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

External library:

外部图书馆:

https://github.com/SheetJS/js-xls