java批量数据导出多个excel,为什么老是只生成一个excel文件 5
publicvoidexportexcel(HttpServletRequestrequest,HttpServletResponseresponse)throwsExc...
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<Map<String, Object>> lists = baseService.findByAll(volunteerFormMap);
for (Map<String, Object> map2 : lists) {
Map<String, String> map1 = new HashMap<String, String>();
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();
} 展开
// 为模板中变量赋值
// 传递模板地址和要操作的页签
ExcelExp excel = new XssExcelExp("../../excel/volunteer.xlsx", 0);
VolunteerFormMap volunteerFormMap = findHasHMap(VolunteerFormMap.class);
volunteerFormMap.put("mapper_id","VolunteerMapper.findvolunteer");
List<Map<String, Object>> lists = baseService.findByAll(volunteerFormMap);
for (Map<String, Object> map2 : lists) {
Map<String, String> map1 = new HashMap<String, String>();
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();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |