【发布时间】:2017-02-17 06:23:22
【问题描述】:
我是 angularjs 新手,我正在尝试导出数据 xlsx 格式,但是 我的数据没有来,任何人都可以帮助我解决如何导出 因为我也解析了 json 数据 csv 但如果有的话仍然可以帮助它 很容易,请把它放在小提琴中并发送给我,谢谢 前进。
<html ng-app="myApp">
<script src="https://rawgithub.com/eligrey/FileSaver.js/master/FileSaver.js" type="text/javascript"></script>
<script src="http://alasql.org/console/alasql.min.js"></script>
<script src="http://alasql.org/console/xlsx.core.min.js"></script>
<button ng-click="exportData()" class="btn btn-primary" style="float:right;padding-right:10px;">Export <i class="fa fa-arrow-down"></i></button>
</html>
js文件是
var app=angular.module('myApp',[]);
app.controller('exportreportController', ['$stateParams','$rootScope', '$scope', '$state', '$location', 'dashboardService', 'Flash','$http','$timeout',
function ($stateParams,$rootScope, $scope, $state, $location, dashboardService, Flash,$http,$timeout) {
$scope.inverters = [
{
"InvDetails": "UPS",
"LstRecords": [
{
"Id": 1,
"Invertor_Id": 1,
"Time_of_Reading": "20170214",
"Lastreading": 0,
"Readingby": 0
},
{
"Id": 87,
"Invertor_Id": 1,
"Time_of_Reading": "20170215",
"Lastreading": 5,
"Readingby": 10
},
{
"Id": 110,
"Invertor_Id": 1,
"Time_of_Reading": "20170216",
"Lastreading": 10,
"Readingby": 92
},
{
"Id": 111,
"Invertor_Id": 1,
"Time_of_Reading": "20170216",
"Lastreading": 92,
"Readingby": 95
}
]
},
{
"InvDetails": "Power Supply",
"LstRecords": [
{
"Id": 2,
"Invertor_Id": 2,
"Time_of_Reading": "20170214",
"Lastreading": 0,
"Readingby": 0
},
{
"Id": 88,
"Invertor_Id": 2,
"Time_of_Reading": "20170215",
"Lastreading": 7,
"Readingby": 13
},
{
"Id": 109,
"Invertor_Id": 2,
"Time_of_Reading": "20170216",
"Lastreading": 13,
"Readingby": 25
},
{
"Id": 112,
"Invertor_Id": 2,
"Time_of_Reading": "20170216",
"Lastreading": 25,
"Readingby": 49
}
]
}
];
$scope.exportData = function () {
//alert("exporting");
// var blob = new Blob([document.getElementById('example1').innerHTML], {
// type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
// });
// saveAs(blob, "Report.xls");
var data="";
$scope.headers=[];
angular.forEach($scope.inverters,function(value,key){
// debugger
var we=value.InvDetails;
$scope.headers.push(we);
$scope.last=value.LstRecords;
angular.forEach($scope.last,function(value,key){
data={
"Id": value.Id,
"Invertor_Id": value.Invertor_Id,
"Time_of_Reading":value.Time_of_Reading,
"Lastreading": value.Lastreading,
"Readingby": value.Readingby
};
})
})
$scope.result=[];
$scope.result0=[];
$scope.result.push({
"Invertor1":JSON.stringify(data)
})
// debugger
alasql('SELECT * INTO XLSX("john.xlsx",{headers:true}) FROM ?',[$scope.result]);
};
}]);
我需要导出这个 csv 或 xlsx 请帮我解决这个问题 在谷歌搜索,但我没有得到确切的解决方案....请 帮帮我。只是我想以报告方式导出数据,因为它是 报告生成。
【问题讨论】:
标签: javascript angularjs csv