假设数据是您在评论会话中提供的链接。以下函数将 转换[object object]
为对象数组,允许导出为 CSV 文件。
//initialize an empty array ready for export as csv
$scope.exportCsvFile = [];
//$scope.data is the valid json data you provided on the comment session
//you just assign the json data to $scope.data
angular.forEach($scope.data, function(collegeData){
var labbox = collegeData.data.labbox;
angular.forEach(collegeData.data.timeseriesdata, function(singleData){
var temp = {
name: labbox
};
angular.forEach(singleData, function(value, key){
temp[key] = value;
});
$scope.exportCsvFile.push(temp);
});
});
在函数之后,您的$scope.exportCsvFile
数组将如下所示:
[
{name: 'Stevens', faculty: 1, student, 949, from: "17:30", to: "17:42"},
{name: 'Stevens', faculty: 0.99, student, 949, from: "17:42", to: "17:54"},
{name: 'Stevens', faculty: 0.97, student, 1380, from: "17:54", to: "17:42"},
{...}
]
在此之后,您可以导出文件:
$scope.Excelexport = function() {
alasql('SELECT * INTO XLSX("example.xlsx",{headers:true}) FROM ?',[$scope.exportCsvFile]);
}
CSV 文件应如下所示:
Name | Faculty | Student | From | To
---------------------------------------------------------
Stevens| 1 | 949 | 17:30 | 17:42
---------------------------------------------------------
Stevens| 0.99 | 1090 | 17:42 | 17:54
---------------------------------------------------------
如果这仍然不能解决您的问题,您可以查看一个名为ng-Csv的 AngularJS 指令。它在字体端将数据导出为 csv 文件。希望能帮助到你!!