angularjs实现Excel导出
< 返回列表时间: 2018-07-10来源:开源中国
HDC调试需求开发(15万预算),能者速来!>>>
1、controller.js

hkdd.excel=function(){
var hkkds={
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
"zt": hkdd.searchForm.hkzt,
"realname":hkdd.searchForm.realname
};

hkdd_service.excelport(hkkds).then(function(res){
hkdd.list=res.list;
hkdd.searchForm=res.page;
});
}
2、service.js
service.excelport = function(searchForm){

/*
var res = $http({ url: baseUrl+'/hkdd/excelexport',
method: "POST",//接口方法
params: searchForm,
headers: {
'Content-type': 'application/json'
},
responseType: 'arraybuffer'
}).success(function (data) {
alert(data);
var blob = new Blob([data], {type: "application/vnd.ms-excel"});
var objectUrl = URL.createObjectURL(blob);
var filename="还款订单"+'.xls';
if (window.navigator.msSaveOrOpenBlob) {// For IE:
navigator.msSaveBlob(blob, filename);
}else{ // For other browsers:
URL.revokeObjectURL(objectUrl);
}
}).error(function (data) {
alert(data.message);
});

return res;*/
3、后台代码
@RequestMapping(value = "/ngres/hkdd/excelexport")
public void excelexcport(@RequestBody String content,HttpServletRequest request, HttpServletResponse response) throws ParseException {
JSONObject jsonObj = JSONObject.fromObject(content);
// 分页对象
Page page = getPage(jsonObj);
TcMemberLoan record = new TcMemberLoan();
if(jsonObj.containsKey("realname")){
record.setRealname(jsonObj.getString("realname"));
System.out.println("bm:"+jsonObj.getString("realname"));
}
if(jsonObj.containsKey("zt")){
record.setZt(jsonObj.getString("zt"));
}

List<TcMemberLoan> olist = tcMemberLoanService.selectByDdxx(record);
Map<String, Object> map = new HashMap<String, Object>();
map.put("list", olist);
map.put("status", ExcelEnum.DDGL.getCode());
String out = PoiCxgl.exportExcel(map,request);
DownLoad.download(out, response);
return;
}



后台是已经生成了文件,我怎样在前端获取并下载呢;以前用jQuery的话,直接是window.location.href=”路径”,页面就会直接下载,Angularjs中该如何实现呢??

热门排行