原文地址:http://www.cnblogs.com/xujanus/p/5985644.html
html
<button class="btn btn-info" ng-click="getDownloadLink()">導出查詢結果</button>
js
// 導出查詢結果 $scope.getDownloadLink = function () { var url = $rootScope.interfaceCtx + '/salesorder/exportOrderList.do'; var params = { bizType:$scope.selectOrderType, bizNo:$scope.selectOrderTypeRefCode, channelId:$scope.channelId, prodId:$scope.prodId, orgId:$scope.orgId, userId:$scope.buyerAccountId, dateType:$scope.selectTimeType, dateStart:$scope.effStartDate, dateEnd:$scope.effEndDate, orderStatus:$scope.selectInsureState, promoter:$scope.promoterAccountId, holderId:$scope.policyHolderId, insuredId:$scope.insuredPersonId, }; $http.post(url,params,{responseType: 'arraybuffer'}).success(function (res) {
//begin var blob = new Blob([res], {type: "application/vnd.ms-excel"}); var objectUrl = URL.createObjectURL(blob); var aForExcel = $("<a><span class='forExcel'>下載excel</span></a>").attr("href",objectUrl); $("body").append(aForExcel); $(".forExcel").click(); aForExcel.remove();
//end }).error(function (res) {$scope.toastError(res);}); };