1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
try { File zipFile = new File(request.getSession().getServletContext ().getRealPath("") + File.separator + "demo.zip"); ZipOutputStream zipOut = null; zipOut = new ZipOutputStream(new FileOutputStream(zipFile)); zipOut.setComment(""); List<List<Map<String, Object>>> lists = ListSplitUtils.splitList(list, 10000); for (int i = 0; i < lists.size(); i++) { List<Map<String, Object>> twoList = new ArrayList<Map<String, Object>>(); twoList.addAll(lists.get(i)); Workbook wb = ExcelExportUtil.exportExcel(params, entityList, twoList); zipOut.putNextEntry(new ZipEntry("demo" + i + ".xlsx")); wb.write(zipOut); zipOut.flush(); } zipOut.close(); BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFile.getPath())); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); response.reset(); OutputStream toClient = new BufferedOutputStream (response.getOutputStream()); response.setContentType("application/octet-stream"); if (zipFile.getName() == null || zipFile.getName() == "") { response.setHeader("Content-Disposition", "attachment;filename=" + new String(zipFile.getName().getBytes("UTF-8"), "ISO-8859-1")); } else { response.setHeader("Content-Disposition", "attachment;filename=" + new String(zipFile.getName().getBytes("UTF-8"), "ISO-8859-1")); } toClient.write(buffer); toClient.flush(); toClient.close(); zipFile.delete(); } catch (IOException ex) { ex.printStackTrace(); }
|
近期评论