简体   繁体   English

如何将json数组对象转换为csv格式并将其导出到离子应用程序的excel文件中

[英]how to convert json array object into csv format and export it in excel file in an ionic app

我是离子框架的新手,正在开发一个应用程序,其中需要将来自$ HTTP.post方法的数据转换为CSV格式,然后单击按钮应将其下载为.xsl格式,我已经搜索了很多关于它的文章,但是没有用..请帮助我...谢谢。

There is a similar question here.. Angular.js generate csv file from json data 这里有一个类似的问题。Angular.js从json数据生成csv文件

If you're using ionic, I would assume angular, and therefore recommend this directive that turns arrays and objects into downloadable CSV files. 如果您使用的是离子型,我会假设是倾斜的,因此建议您使用此指令将数组和对象转换为可下载的CSV文件。

https://github.com/asafdav/ng-csv https://github.com/asafdav/ng-csv

If you don't want to read the accepted answers. 如果您不想阅读已接受的答案。 Here's the sklinny. 这是sklinny。

var myapp = angular.module('myapp', ['ngSanitize', 'ngCsv'])

Add ng-csv directive to the wanted element, example: 将ng-csv指令添加到所需元素,例如:

<button type="button" ng-csv="getArray" filename="test.csv">Export</button>

In your controller, getarray is just your array (the json you'd get back from your request). 在您的控制器中,getarray只是您的数组(您将从请求中获取的json)。

 $scope.getArray = [{a: 1, b:2}, {a:3, b:4}];

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

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