导出时自由选择路径的代码如下:
1、后台输出Excel文件代码:
OutputStream output = response.getOutputStream();
response.reset();
response.setHeader("Content-disposition", "attachment; filename=" + path);
response.setContentType("Content-Type:application/vnd.ms-excel ");
wb.write(output);
output.close();
2、前端代码:
window.open("getExcelList","_blank");
导出excel数据
* @param id
* @param m
* @return
*/
@RequestMapping("/exportExcel")
public void exportExcel(@RequestParam("id") Integer id, Model m,HttpServletRequest req, HttpServletResponse resp) {
try {
ExportExcel
String[] headers = {"最迟还款日", "还款金额","剩余几天","逾期几天", "罚息","是否垫付","状态","是否发放收益"};
List
List
for (int i = 0; i < plans.size(); i++) {
P2pLoanPlanVo p2pLoanPlanVo = new P2pLoanPlanVo();
p2pLoanPlanVo.setRepayDate(plans.get(i).getRepayDate());
p2pLoanPlanVo.setRepayAmount(plans.get(i).getRepayAmount());
if(plans.get(i).getRepayDays() >= 0 && plans.get(i).getStatus() == 0){
p2pLoanPlanVo.setRepayDays(plans.get(i).getRepayDays());
}else{
p2pLoanPlanVo.setRepayDays(0);
}
if(plans.get(i).getRepayDays() < 0 && plans.get(i).getStatus() == 0){
p2pLoanPlanVo.setRepayYqDays(-plans.get(i).getRepayDays());
}else{
p2pLoanPlanVo.setRepayYqDays(0);
}
主要代码如下:
后台输出Excel文件代码:
OutputStream output = response.getOutputStream();
response.reset();
response.setHeader("Content-disposition", "attachment; filename=" + path);
response.setContentType("Content-Type:application/vnd.ms-excel ");
wb.write(output);
output.close();
前端代码:window.open("getExcelList","_blank");
做个临时文件,在重定向到这个临时文件,浏览器就会选择下载
可以用pageoffice导出excel. pageoffice 调用的是本地的office,导出excel可以弹出另存的对话框,用户可以选择自己想要的位置进行保存.