List of usage examples for org.apache.poi.xssf.streaming SXSSFWorkbook setCompressTempFiles
public void setCompressTempFiles(boolean compress)
From source file:com.daphne.es.showcase.excel.service.ExcelDataService.java
License:Apache License
/** * ???/*from w w w. ja va 2 s . c o m*/ * excel 2007 ?sheet1048576 * @param user * @param contextRootPath * @param searchable */ @Async public void exportExcel2007(final User user, final String contextRootPath, final Searchable searchable) { int rowAccessWindowSize = 1000; //??? int perSheetRows = 100000; //?sheet 10w? int totalRows = 0; // Long maxId = 0L;//??id String fileName = generateFilename(user, contextRootPath, "xlsx"); File file = new File(fileName); BufferedOutputStream out = null; SXSSFWorkbook wb = null; try { long beginTime = System.currentTimeMillis(); wb = new SXSSFWorkbook(rowAccessWindowSize); wb.setCompressTempFiles(true);//?gzip while (true) { Sheet sheet = wb.createSheet(); Row headerRow = sheet.createRow(0); Cell idHeaderCell = headerRow.createCell(0); idHeaderCell.setCellValue("?"); Cell contentHeaderCell = headerRow.createCell(1); contentHeaderCell.setCellValue(""); totalRows = 1; Page<ExcelData> page = null; do { searchable.setPage(0, pageSize); // if (!searchable.containsSearchKey("id_in")) { searchable.addSearchFilter("id", SearchOperator.gt, maxId); } page = findAll(searchable); for (ExcelData data : page.getContent()) { Row row = sheet.createRow(totalRows); Cell idCell = row.createCell(0); idCell.setCellValue(data.getId()); Cell contentCell = row.createCell(1); contentCell.setCellValue(data.getContent()); maxId = Math.max(maxId, data.getId()); totalRows++; } //clear entity manager RepositoryHelper.clear(); } while (page.hasNext() && totalRows <= perSheetRows); if (!page.hasNext()) { break; } } out = new BufferedOutputStream(new FileOutputStream(file)); wb.write(out); IOUtils.closeQuietly(out); if (needCompress(file)) { fileName = compressAndDeleteOriginal(fileName); } long endTime = System.currentTimeMillis(); Map<String, Object> context = Maps.newHashMap(); context.put("seconds", (endTime - beginTime) / 1000); context.put("url", fileName.replace(contextRootPath, "")); notificationApi.notify(user.getId(), "excelExportSuccess", context); } catch (Exception e) { IOUtils.closeQuietly(out); log.error("excel export error", e); Map<String, Object> context = Maps.newHashMap(); context.put("error", e.getMessage()); notificationApi.notify(user.getId(), "excelExportError", context); } finally { // ? wb.dispose(); } }
From source file:com.luna.showcase.excel.service.ExcelDataService.java
License:Apache License
/** * ???//from w w w . j a va 2 s . c om * excel 2007 ?sheet1048576 * @param user * @param contextRootPath * @param searchable */ @Async public void exportExcel2007(final User user, final String contextRootPath, final Searchable searchable) { int rowAccessWindowSize = 1000; //??? int perSheetRows = 100000; //?sheet 10w? int totalRows = 0; // Long maxId = 0L;//??id String fileName = generateFilename(user, contextRootPath, "xlsx"); File file = new File(fileName); BufferedOutputStream out = null; SXSSFWorkbook wb = null; try { long beginTime = System.currentTimeMillis(); wb = new SXSSFWorkbook(rowAccessWindowSize); wb.setCompressTempFiles(true);//?gzip while (true) { Sheet sheet = wb.createSheet(); Row headerRow = sheet.createRow(0); Cell idHeaderCell = headerRow.createCell(0); idHeaderCell.setCellValue("?"); Cell contentHeaderCell = headerRow.createCell(1); contentHeaderCell.setCellValue(""); totalRows = 1; Page<ExcelData> page = null; do { searchable.setPage(0, pageSize); // if (!searchable.containsSearchKey("id_in")) { searchable.addSearchFilter("id", SearchOperator.gt, maxId); } page = findAll(searchable); for (ExcelData data : page.getContent()) { Row row = sheet.createRow(totalRows); Cell idCell = row.createCell(0); idCell.setCellValue(data.getId()); Cell contentCell = row.createCell(1); contentCell.setCellValue(data.getContent()); maxId = Math.max(maxId, data.getId()); totalRows++; } //clear entity manager RepositoryHelper.clear(); } while (page.hasNextPage() && totalRows <= perSheetRows); if (!page.hasNextPage()) { break; } } out = new BufferedOutputStream(new FileOutputStream(file)); wb.write(out); IOUtils.closeQuietly(out); if (needCompress(file)) { fileName = compressAndDeleteOriginal(fileName); } long endTime = System.currentTimeMillis(); Map<String, Object> context = Maps.newHashMap(); context.put("seconds", (endTime - beginTime) / 1000); context.put("url", fileName.replace(contextRootPath, "")); notificationApi.notify(user.getId(), "excelExportSuccess", context); } catch (Exception e) { IOUtils.closeQuietly(out); log.error("excel export error", e); Map<String, Object> context = Maps.newHashMap(); context.put("error", e.getMessage()); notificationApi.notify(user.getId(), "excelExportError", context); } finally { // ? wb.dispose(); } }
From source file:de.unioninvestment.eai.portal.portlet.crud.export.ExcelExportTask.java
License:Apache License
@Override protected TableExport createExport() { SXSSFWorkbook wkbk = new SXSSFWorkbook(50); wkbk.setCompressTempFiles(true); ExcelExportWithProgress excelExport = new ExcelExportWithProgress(vaadinTable, wkbk, "ExportCallback", null, getFilename(), false);// w w w. j a va 2 s. c o m excelExport.setExportWindow("_blank"); excelExport.setMimeType(EXCEL_XSLX_MIMETYPE); excelExport.setRowHeaders(true); excelExport.excludeCollapsedColumns(); applyExcelFormatForColumns(excelExport); return excelExport; }
From source file:de.unioninvestment.eai.portal.portlet.crud.export.streaming.ExcelExporter.java
License:Apache License
private Workbook createWorkbook() { SXSSFWorkbook workbook = new SXSSFWorkbook(excelRowAccessWindowSize); workbook.setCompressTempFiles(true); return workbook; }
From source file:org.apache.tika.eval.reports.Report.java
License:Apache License
private void dumpXLSX(Connection c, Path reportsRoot) throws IOException, SQLException { Statement st = c.createStatement(); Path out = reportsRoot.resolve(reportFilename); Files.createDirectories(out.getParent()); SXSSFWorkbook wb = new SXSSFWorkbook(new XSSFWorkbook(), 100, true, true); wb.setCompressTempFiles(true); defaultIntegerFormatter.reset(wb.getXSSFWorkbook()); defaultDoubleFormatter.reset(wb.getXSSFWorkbook()); sqlCellStyle = wb.createCellStyle(); sqlCellStyle.setVerticalAlignment(VerticalAlignment.TOP); sqlCellStyle.setWrapText(true);//from www . j a v a 2 s . c om try { dumpReportToWorkbook(st, wb); } finally { try (OutputStream os = Files.newOutputStream(out)) { wb.write(os); } finally { wb.dispose(); } } }
From source file:org.jberet.support.io.ExcelStreamingItemWriter.java
License:Open Source License
@Override protected Workbook createWorkbook(final InputStream templateInputStream) throws IOException, InvalidFormatException { if (templateInputStream != null) { final Workbook template = WorkbookFactory.create(templateInputStream); if (template instanceof XSSFWorkbook) { workbook = compressTempFiles == Boolean.TRUE ? new SXSSFWorkbook((XSSFWorkbook) template, -1, compressTempFiles) : new SXSSFWorkbook((XSSFWorkbook) template, -1); return template; } else {//from w w w . j a v a2 s. c o m throw SupportMessages.MESSAGES.incompatibleExcelFileFormat(templateResource); } } else if (resource.endsWith("xlsx")) { final SXSSFWorkbook workbook1 = new SXSSFWorkbook(-1); if (compressTempFiles == Boolean.TRUE) { workbook1.setCompressTempFiles(true); } workbook = workbook1; } else { throw SupportMessages.MESSAGES.incompatibleExcelFileFormat(resource); } return null; }
From source file:org.primefaces.component.export.ExcelXStreamExporter.java
License:Apache License
@Override protected Workbook createWorkBook() { SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(100); sxssfWorkbook.setCompressTempFiles(true); return sxssfWorkbook; }
From source file:tools.xor.service.AggregateManager.java
License:Apache License
/** * Generate the Excel sheets based on entities and collections * TODO: Should the map be topologically ordered? * @param to root entity/*w ww . j a va 2s. c o m*/ * @param sheetBO map of the sheet name and the entities/relationships within that sheet * @return the generated Excel workbook */ private Workbook processSheetBO(BusinessObject to, Map<String, List<BusinessObject>> sheetBO) { SXSSFWorkbook wb = new SXSSFWorkbook(); wb.setCompressTempFiles(true); List<BusinessObject> entityBOList = new LinkedList<BusinessObject>(); entityBOList.add(to); createBOSheet(wb, Constants.XOR.EXCEL_ENTITY_SHEET, null, entityBOList, null); int sheetNo = 1; Map<String, String> sheetMap = new HashMap<String, String>(); for (Map.Entry<String, List<BusinessObject>> entry : sheetBO.entrySet()) { // Create a sheet String sheetName = Constants.XOR.EXCEL_SHEET_PREFIX + sheetNo++; sheetMap.put(entry.getKey(), sheetName); createBOSheet(wb, sheetName, entry.getKey(), entry.getValue(), null); } writeSheetMap(wb, sheetMap); return wb; }