$http({
method : "post",
url : Constant.prefixUrl+"/customerQueryCount/exportMonthReport",
timeout : Constant.timeout,
responseType: "blob" //注意此参数
}).success(function(data, status, headers, config){
var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
if(blob.size>0){
var fileName = $rootScope.currentAdminUserId +""+ (new Date()).getTime();
var a = document.createElement("a");
document.body.appendChild(a);
a.download = fileName;
a.href = URL.createObjectURL(blob);
a.click();
}else{
deferred.resolve("下载报表失败");
}
}).error(function(data, status, headers, config){
commonService.goLoginPage(status);
FileInputStream fis;
byte[] b = null;
try {
fis = new FileInputStream(file);
b = new byte[fis.available()];
fis.read(b);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setHeader("Content-Disposition", "attachment;filename=" + fu + ".xlsx" );// 为文件命名
response.addHeader("content-type", "application/pdf");
return b;
method : "post",
url : Constant.prefixUrl+"/customerQueryCount/exportMonthReport",
timeout : Constant.timeout,
responseType: "blob" //注意此参数
}).success(function(data, status, headers, config){
var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
if(blob.size>0){
var fileName = $rootScope.currentAdminUserId +""+ (new Date()).getTime();
var a = document.createElement("a");
document.body.appendChild(a);
a.download = fileName;
a.href = URL.createObjectURL(blob);
a.click();
}else{
deferred.resolve("下载报表失败");
}
}).error(function(data, status, headers, config){
commonService.goLoginPage(status);
});
后台:
@POST
@Path("/export2")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public byte[] export2(@RequestBody String params, @Context HttpServletResponse response) {
FileInputStream fis;
byte[] b = null;
try {
fis = new FileInputStream(file);
b = new byte[fis.available()];
fis.read(b);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setHeader("Content-Disposition", "attachment;filename=" + fu + ".xlsx" );// 为文件命名
response.addHeader("content-type", "application/pdf");
return b;