java 导出多个excel_java批量数据导出多个excel,为什么老是只生成一个excel文件

publicvoidexportexcel(HttpServletRequestrequest,HttpServletResponseresponse)throwsException{//为模板中变量赋值//传递模板地址和要操作的页签ExcelExpexcel=newXssExcelExp(".....

public void exportexcel(HttpServletRequest request, HttpServletResponse response) throws Exception {

// 为模板中变量赋值

// 传递模板地址和要操作的页签

ExcelExp excel = new XssExcelExp("../../excel/volunteer.xlsx", 0);

VolunteerFormMap volunteerFormMap = findHasHMap(VolunteerFormMap.class);

volunteerFormMap.put("mapper_id","VolunteerMapper.findvolunteer");

List> lists = baseService.findByAll(volunteerFormMap);

for (Map map2 : lists) {

Map map1 = new HashMap();

map1.put("name", (String) map2.get("name"));

map1.put("gender", (String) map2.get("gender"));

map1.put("education", (String) map2.get("education"));

map1.put("politicalAff", (String) map2.get("political_aff"));

map1.put("workUnit", (String) map2.get("work_unit"));

map1.put("unitAddress", (String) map2.get("unit_address"));

map1.put("address", (String) map2.get("address"));

map1.put("phoneNumber", (String) map2.get("phoneNumber"));

map1.put("idNumber", (String) map2.get("id_number"));

map1.put("hobby", (String) map2.get("hobby"));

map1.put("contactInfo", (String) map2.get("contact_info"));

map1.put("introducer", (String) map2.get("introducer"));

map1.put("partinTime", (String) map2.get("partin_time"));

excel.replaceExcelData(map1);

// 导出,此处只封装了浏览器下载方式

// 调用downloadExcel,返回输出流给客户端

String fileName = (String) map2.get("name") + ".xlsx";

excel.downloadExcel(response, fileName);

}

}

public void downloadExcel(HttpServletResponse response, String filaName) throws IOException {

String encodeFileName = URLEncoder.encode(filaName, "UTF-8");

response.addHeader("Content-Disposition", "attachment;filename=" + encodeFileName);

//response.setHeader("Accept-Ranges", "bytes");

ServletOutputStream out = response.getOutputStream();

xssWb.write(out);

out.flush();

out.close();

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值