简体   繁体   English

如何在Angular JS中将JSON数据导出到Excel?

[英]How to export json data to excel in angular js?

可以将从Angular JS中的POST方法获取的json数据导出为.csv或.xls格式的excel吗?

All you have to do is to send a request to your server and this one generates the file, for example csv, and add those headers to the request: 您要做的就是向服务器发送一个请求,然后生成一个文件(例如csv),并将这些标头添加到请求中:

header('Content-Description: File Transfer');
header("Content-Type: application/csv") ;

Then your browser will download the file automatically. 然后,您的浏览器将自动下载文件。

If you need to generate the file in the browser you can use ng-csv but in my opinion I would use the first one. 如果您需要在浏览器中生成文件,则可以使用ng-csv,但我认为我会使用第一个。

before answering your question i would like to know what type of data you are exporting to excel or csv . 在回答您的问题之前,我想知道您要导出到excel或csv的数据类型。

If ur using ng-csv directive then you can't export your data to excel files . 如果您使用ng-csv指令,则无法将数据导出到excel文件。 If u are planning ahead to export in other file formats also then there ia a library u can use . 如果您正计划以其他文件格式导出,那么您可以使用一个库。

alasql.js alasql.js

Here is a link if u are interesed to know more about this library 如果您感兴趣以了解有关此库的更多信息,这是一个链接

https://github.com/agershun/alasql https://github.com/agershun/alasql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM