Angularjs 导出excel表格

//导出excel表
$scope.exportOrder = function () {
$scope.datetime.startTime=$scope.year+"-"+ $scope.lastmounth+"-"+$scope.lastday;
$scope.datetime.endTime=$scope.yearD+"-"+ $scope.mounthD+"-"+"25";
$scope.datetime.type= $scope.selectway;
$http({
url: 'kpis/export/inp',
method: "POST",
headers: {
'Content-type': 'application/json'
},
params: $scope.datetime,
responseType: 'arraybuffer'
}).success(function (data) {
var blob = new Blob([data], {type: "application/vnd.ms-excel"});
var objectUrl = URL.createObjectURL(blob);
var filename="报表"+$scope.yearD+"-"+ $scope.mounthD+'.xls';
if (window.navigator.msSaveOrOpenBlob) {// For IE:
navigator.msSaveBlob(blob, filename);
}else{ // For other browsers:
URL.revokeObjectURL(objectUrl);
}
}).error(function(data){
alert(data.message);
});
};
posted @ 2017-04-07 10:42  liucong2016  阅读(5869)  评论(0编辑  收藏  举报