Java Code Examples for org.apache.poi.xssf.streaming.SXSSFWorkbook#close()
The following examples show how to use
org.apache.poi.xssf.streaming.SXSSFWorkbook#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PoiTest.java From easyexcel with Apache License 2.0 | 8 votes |
@Test public void testread() throws IOException { String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx"; SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file)); Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0); // // Cell cell = xssfSheet.getRow(0).createCell(9); String file1 = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx"; SXSSFWorkbook xssfWorkbook1 = new SXSSFWorkbook(new XSSFWorkbook(file1)); Sheet xssfSheet1 = xssfWorkbook1.getXSSFWorkbook().getSheetAt(0); // Cell cell1 = xssfSheet1.getRow(0).createCell(9); xssfWorkbook.close(); xssfWorkbook1.close(); }
Example 2
Source File: ExcelBoot.java From excel-boot with Artistic License 2.0 | 7 votes |
/** * 导出-导入模板 * * @param data * @throws Exception */ public void exportTemplate() { SXSSFWorkbook sxssfWorkbook = null; try { try { verifyResponse(); verifyParams(); ExcelEntity excelMapping = ExcelMappingFactory.loadExportExcelClass(excelClass, fileName); ExcelWriter excelWriter = new ExcelWriter(excelMapping, pageSize, rowAccessWindowSize, recordCountPerSheet, openAutoColumWidth); sxssfWorkbook = excelWriter.generateTemplateWorkbook(); download(sxssfWorkbook, httpServletResponse, URLEncoder.encode(fileName + ".xlsx", "UTF-8")); } finally { if (sxssfWorkbook != null) { sxssfWorkbook.close(); } if (httpServletResponse != null && httpServletResponse.getOutputStream() != null) { httpServletResponse.getOutputStream().close(); } } } catch (Exception e) { throw new ExcelBootException(e); } }
Example 3
Source File: ExcelBoot.java From excel-boot with Artistic License 2.0 | 6 votes |
/** * 用于浏览器导出 * * @param param * @param exportFunction * @param ExportFunction * @param <R> * @param <T> */ public <R, T> void exportResponse(R param, ExportFunction<R, T> exportFunction) { SXSSFWorkbook sxssfWorkbook = null; try { try { verifyResponse(); sxssfWorkbook = commonSingleSheet(param, exportFunction); download(sxssfWorkbook, httpServletResponse, URLEncoder.encode(fileName + ".xlsx", "UTF-8")); } finally { if (sxssfWorkbook != null) { sxssfWorkbook.close(); } if (httpServletResponse != null && httpServletResponse.getOutputStream() != null) { httpServletResponse.getOutputStream().close(); } } } catch (Exception e) { throw new ExcelBootException(e); } }
Example 4
Source File: ExcelBoot.java From excel-boot with Artistic License 2.0 | 6 votes |
/** * 通过OutputStream导出excel文件,一般用于异步导出大Excel文件到ftp服务器 * * @param param * @param exportFunction * @param ExportFunction * @param <R> * @param <T> * @return */ public <R, T> OutputStream generateStream(R param, ExportFunction<R, T> exportFunction) throws IOException { SXSSFWorkbook sxssfWorkbook = null; try { verifyStream(); sxssfWorkbook = commonSingleSheet(param, exportFunction); sxssfWorkbook.write(outputStream); return outputStream; } catch (Exception e) { log.error("生成Excel发生异常! 异常信息:", e); if (sxssfWorkbook != null) { sxssfWorkbook.close(); } throw new ExcelBootException(e); } }
Example 5
Source File: ExcelBoot.java From excel-boot with Artistic License 2.0 | 6 votes |
/** * 用于浏览器分sheet导出 * * @param param * @param exportFunction * @param ExportFunction * @param <R> * @param <T> */ public <R, T> void exportMultiSheetResponse(R param, ExportFunction<R, T> exportFunction) { SXSSFWorkbook sxssfWorkbook = null; try { try { verifyResponse(); sxssfWorkbook = commonMultiSheet(param, exportFunction); download(sxssfWorkbook, httpServletResponse, URLEncoder.encode(fileName + ".xlsx", "UTF-8")); } finally { if (sxssfWorkbook != null) { sxssfWorkbook.close(); } } } catch (Exception e) { throw new ExcelBootException(e); } }
Example 6
Source File: ExcelBoot.java From excel-boot with Artistic License 2.0 | 6 votes |
/** * 通过OutputStream分sheet导出excel文件,一般用于异步导出大Excel文件到ftp服务器 * * @param param * @param exportFunction * @param ExportFunction * @param <R> * @param <T> * @return */ public <R, T> OutputStream generateMultiSheetStream(R param, ExportFunction<R, T> exportFunction) throws IOException { SXSSFWorkbook sxssfWorkbook = null; try { verifyStream(); sxssfWorkbook = commonMultiSheet(param, exportFunction); sxssfWorkbook.write(outputStream); return outputStream; } catch (Exception e) { log.error("分Sheet生成Excel发生异常! 异常信息:", e); if (sxssfWorkbook != null) { sxssfWorkbook.close(); } throw new ExcelBootException(e); } }
Example 7
Source File: PoiTest.java From easyexcel with Apache License 2.0 | 6 votes |
@Test public void lastRowNum233() throws IOException { String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx"; Workbook xx = new XSSFWorkbook(file); System.out.println(new File(file).exists()); SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(); Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0); Cell cell = xssfSheet.getRow(0).createCell(9); cell.setCellValue("testssdf是士大夫否t"); FileOutputStream fileout = new FileOutputStream("d://test/r2" + System.currentTimeMillis() + ".xlsx"); xssfWorkbook.write(fileout); xssfWorkbook.close(); }
Example 8
Source File: PoiTest.java From easyexcel with Apache License 2.0 | 6 votes |
@Test public void lastRowNum2333() throws IOException, InvalidFormatException { String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx"; XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new File(file)); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(xssfWorkbook); Sheet xssfSheet = xssfWorkbook.getSheetAt(0); Cell cell = xssfSheet.getRow(0).createCell(9); cell.setCellValue("testssdf是士大夫否t"); FileOutputStream fileout = new FileOutputStream("d://test/r2" + System.currentTimeMillis() + ".xlsx"); sxssfWorkbook.write(fileout); sxssfWorkbook.dispose(); sxssfWorkbook.close(); xssfWorkbook.close(); }
Example 9
Source File: PoiTest.java From easyexcel with Apache License 2.0 | 5 votes |
@Test public void lastRowNum255() throws IOException, InvalidFormatException { String file = "D:\\test\\complex.xlsx"; XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new File(file)); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(xssfWorkbook); Sheet xssfSheet = xssfWorkbook.getSheetAt(0); xssfSheet.shiftRows(1, 4, 10, true, true); FileOutputStream fileout = new FileOutputStream("d://test/r2" + System.currentTimeMillis() + ".xlsx"); sxssfWorkbook.write(fileout); sxssfWorkbook.dispose(); sxssfWorkbook.close(); xssfWorkbook.close(); }
Example 10
Source File: PoiTest.java From easyexcel with Apache License 2.0 | 5 votes |
@Test public void lastRowNum23443() throws IOException { String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx"; SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file)); Sheet xssfSheet = xssfWorkbook.getSheetAt(0); FileOutputStream fileout = new FileOutputStream("d://test/r2" + System.currentTimeMillis() + ".xlsx"); xssfWorkbook.write(fileout); xssfWorkbook.close(); }
Example 11
Source File: ReportExcelUtil.java From roncoo-education with MIT License | 4 votes |
public static void exportExcelForLecturerProfit(HttpServletResponse response, Page<LecturerProfitVO> result) throws IOException { // 创建一个workbook 对应一个excel文件 final SXSSFWorkbook workBook = new SXSSFWorkbook(); SXSSFSheet sheet = workBook.createSheet("讲师分润报表"); // 列名和列宽 String[] names = { "讲师名称", "银行卡号", "银行名称", "银行开户名", "讲师分润(元)", "平台分润(元)", "时间" };// 表头 Integer[] widths = { 25, 15, 15, 25, 25, 25, 25 };// 列宽 // 创建第一行 SXSSFRow row = sheet.createRow(0); // 设置第一行样式 CellStyle headStyle = workBook.createCellStyle(); headStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);// 水平居中 headStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中 // 设置第一行字体 Font headFont = workBook.createFont(); headFont.setBold(true); headStyle.setFont(headFont); // 设置第一行单元格内容、单元格样式 for (int i = 0; i < names.length; i++) { SXSSFCell cell = row.createCell(i); cell.setCellValue(names[i]); cell.setCellStyle(headStyle); sheet.setColumnWidth(i, widths[i] * 256); } // 从第二行开始遍历出分润记录表的数据,再写入单元格 SXSSFRow row1 = sheet.createRow(1); int r = 1; for (LecturerProfitVO bean : result.getList()) { row1 = sheet.createRow(r++); row1.createCell(0).setCellValue(bean.getLecturerVO().getLecturerName()); row1.createCell(1).setCellValue(bean.getBankCardNo()); row1.createCell(2).setCellValue(bean.getBankName()); row1.createCell(3).setCellValue(bean.getBankUserName()); row1.createCell(4).setCellValue(bean.getLecturerProfit().doubleValue()); row1.createCell(5).setCellValue(bean.getPlatformProfit().doubleValue()); row1.createCell(6).setCellValue(new SimpleDateFormat("yyyy/MM/dd").format(bean.getGmtCreate())); } try { workBook.write(response.getOutputStream()); response.getOutputStream().flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (response.getOutputStream() != null) response.getOutputStream().close(); if (workBook != null) workBook.close(); } }