代码示例
workbookMap key是excle文件名 value是XSSFWorkbook
标签:String,zip,excel,new,workbookMap,XSSFWorkbook,response,下载,out From: https://www.cnblogs.com/feizai-java/p/16985334.html
public static void downloadExcelForZip(HttpServletResponse response, Map<String, XSSFWorkbook> workbookMap, String zipName) throws IOException {
ZipOutputStream out = null;
try {
response.setContentType("application/*");
response.setHeader("content-disposition", "attachment;filename=" + new String(zipName.getBytes("gb2312"), "ISO8859-1"));
response.setCharacterEncoding("UTF-8");
out = new ZipOutputStream(response.getOutputStream());
Iterator var4 = workbookMap.keySet().iterator();
while(var4.hasNext()) {
String fileName = (String)var4.next();
XSSFWorkbook workbook = (XSSFWorkbook)workbookMap.get(fileName);
ZipEntry entry = new ZipEntry(fileName);
out.putNextEntry(entry);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
bos.writeTo(out);
out.closeEntry();
}
out.flush();
} catch (IOException var12) {
} finally {
if (out != null) {
out.close();
}
}
}