注明:
第一行的:
$rootScope.restful_api.last_output_excel,body_data
这两个值,分别是URL串和post请求的body。其他代码不用变,即可使用。
原文链接:http://www.cnblogs.com/xujanus/p/5985644.html
最近工作中遇到,要使用angularJS的post方法来下载excel的情况。网上找到一个帖子:http://stackoverflow.com/questions/22447952/angularjs-http-post-convert-binary-to-excel-file-and-download ,改动了里面部分代码搞定。
@H_502_22@ 详细代码:$http.post($rootScope.restful_api.last_output_excel,body_data,{responseType: 'arraybuffer'}).success(function(data){ var blob = new Blob([data],{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(); })