本文主要和大家分享angularjs使用webapi导出数据代码实例,希望本文的代码能帮助到大家。
/////导出功能
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);
}
}相关推荐:
以上就是AngularJS使用webApi导出数据的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号