Java 利用poi 导出excel表格如何在导出时自由选择路径?
导出时自由选择路径的代码如下:
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<P2pLoanPlanVo> ex = new ExportExcel<P2pLoanPlanVo>();
String[] headers = {"最迟还款日", "还款金额","剩余几天","逾期几天", "罚息","是否垫付","状态","是否发放收益"};
List<P2pLoanPlanVo> dataset = new ArrayList<P2pLoanPlanVo>();
List<P2pLoanPlan> plans = this.planService.getListByLoan(id);
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);
}