我在kendo网格上有exportChallenges
按钮,通过使用angularJs factory将网格数据导出为excel,我从服务器端收到了休息服务响应(Blob),但它没有提示用户在浏览器上保存,打开或下载选项。
如何使用Angularjs或本机javascript解决此问题?
export.js
$scope.exportChallenges = function() {
processFactory.exportPrcChallenges($stateParams.processId, challengeType);
.success(function(response) {
var blob = new Blob([response.data], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
});
debugger;
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
});
};
答案 0 :(得分:1)
打开blob取决于浏览器(即,IE在API中有自己的实现)。这样做:
var blob = new Blob([response.data], {type: contentType});
//call the save blob API in IE
if(window.navigator && window.navigator.msSaveOrOpenBlob) {
//save or open prompt in IE
//there's a save prompt too, depending on what you need
window.navigator.msSaveOrOpenBlob(blob, "filename");
} else { //other browsers
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}