时间:2021-07-01 10:21:17 帮助过:9人阅读
/////导出功能 self.importExcel = function () { var dataUrl = "http://103.233.7.38:8090/API/_oa/ProjectInfo.asmx/Export"; $http({ method: 'post', url: dataUrl, data: { }, transformRequest: function (data) { return $.param(data); }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, responseType: 'arraybuffer' }).success(function (data) { var blob = new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); var da = new Date(); var fileName = "数据导出" + da.getFullYear() + '-' + (da.getMonth() + 1) + "-" + da.getDate(); self.saveas(blob, fileName); }); }; self.saveas = function (blob, fileName) { if (window.navigator.msSaveOrOpenBlob) { // For IE: navigator.msSaveBlob(blob, fileName+".xlsx"); } else { // For other browsers: var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = fileName + ".xlsx"; link.click(); window.URL.revokeObjectURL(link.href); } }
相关推荐:
Nginx 解决WebApi跨域二次请求实例
让WebAPI 返回JSON格式的数据实例教程
分享WebApi2 文件图片上传与下载功能实例
以上就是AngularJS使用webApi导出数据的详细内容,更多请关注Gxl网其它相关文章!