List of usage examples for org.apache.poi.xssf.streaming SXSSFWorkbook SXSSFWorkbook
public SXSSFWorkbook(int rowAccessWindowSize)
From source file:com.eyeq.pivot4j.export.poi.ExcelExporter.java
License:Common Public License
protected Workbook createWorkbook() { Workbook newWorkbook = null;// w ww . ja va2 s . c o m switch (format) { case XSSF: newWorkbook = new XSSFWorkbook(); break; case HSSF: newWorkbook = new HSSFWorkbook(); break; case SXSSF: newWorkbook = new SXSSFWorkbook(500); break; default: assert false; } return newWorkbook; }
From source file:com.github.igor_kudryashov.utils.excel.ExcelWriter.java
License:Apache License
/** * Default constructor// www . j ava2 s.c om */ public ExcelWriter() { // create new workbook with 100 unflushed records workbook = new SXSSFWorkbook(100); // When a new node is created via createRow() and the total number of // unflushed records would exceed the specified value, then the row with // the lowest index value is flushed and cannot be accessed via getRow() // anymore. // A value of -1 indicates unlimited access. In this case all records // that have not been flushed by a call to flush() are available for // random access. // A value of 0 is not allowed because it would flush any newly created // row without having a chance to specify any cells. }
From source file:com.github.svrtm.xlreport.Excel_2007XL.java
License:Apache License
final static public Body instanceBody(final Header header) { header.init(new SXSSFWorkbook(ROW_ACCESS_WINDOW_SIZE), SpreadsheetVersion.EXCEL2007.getLastRowIndex(), Row07XL.class); header.prepareHeader();// w w w .j a v a 2s . co m return new Body(header); }
From source file:com.github.svrtm.xlreport.Excel_2007XL.java
License:Apache License
final static public Body instanceBody() { return new Body(new SXSSFWorkbook(ROW_ACCESS_WINDOW_SIZE), SpreadsheetVersion.EXCEL2007.getLastRowIndex()); }
From source file:com.github.ukase.service.XlsxRenderer.java
License:Open Source License
public byte[] render(String html) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); SXSSFWorkbook wb = new SXSSFWorkbook(-1); ITextRenderer renderer = provider.getRenderer(html); Document document = renderer.getDocument(); BlockBox box = renderer.getRootBox(); RenderingTableBuilder builder = new RenderingTableBuilder(wb, box); new ElementList(document.getElementsByTagName(TAG_TABLE)).stream().map(builder::build) .forEach(RenderingTable::run); wb.write(baos);/*ww w . j a v a 2 s. co m*/ wb.dispose(); return baos.toByteArray(); }
From source file:com.heimaide.server.common.utils.excel.ExportExcel.java
License:Open Source License
private void initialize(String title, List<String> headerList) { this.wb = new SXSSFWorkbook(500); this.sheet = wb.createSheet("Export"); this.styles = createStyles(wb); // Create title if (StringUtils.isNotBlank(title)) { Row titleRow = sheet.createRow(rownum++); titleRow.setHeightInPoints(30);/*w w w .j a v a 2s .c o m*/ Cell titleCell = titleRow.createCell(0); titleCell.setCellStyle(styles.get("title")); titleCell.setCellValue(title); sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), headerList.size() - 1)); } // Create header if (headerList == null) { throw new RuntimeException("headerList not null!"); } Row headerRow = sheet.createRow(rownum++); headerRow.setHeightInPoints(16); for (int i = 0; i < headerList.size(); i++) { Cell cell = headerRow.createCell(i); cell.setCellStyle(styles.get("header")); String[] ss = StringUtils.split(headerList.get(i), "**", 2); if (ss.length == 2) { cell.setCellValue(ss[0]); Comment comment = this.sheet.createDrawingPatriarch() .createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6)); comment.setString(new XSSFRichTextString(ss[1])); cell.setCellComment(comment); } else { cell.setCellValue(headerList.get(i)); } sheet.autoSizeColumn(i); } for (int i = 0; i < headerList.size(); i++) { int colWidth = sheet.getColumnWidth(i) * 2; sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth); } log.debug("Initialize success."); }
From source file:com.jshuabo.reportcenter.server.service.automoblie.impl.DefaultAutoRecordServiceImpl.java
License:Open Source License
@Override public void importToExcel(Map<String, Object> exprotMap, HttpServletResponse response, HttpServletRequest request, String[] title, String excelName) { Map<String, Object> pageData = autoRecordDataMapper.exprotPageData(exprotMap); SXSSFWorkbook workbook = new SXSSFWorkbook(1000); // keep 100 rows in memory, exceeding rows int flag = 1; // int rowCount = 150000; // ?sheet long count = (Long) pageData.get("COUNT"); long pageSize = rowCount; // ?? long page = 1; if (rowCount < count) { if (count % pageSize == 0) { } else {//w ww .ja va 2 s . c o m page = count / pageSize + 1; } // } Sheet sh = workbook.createSheet(excelName + System.currentTimeMillis()); Row row = sh.createRow((short) 0); // Cell cell = null; CellStyle[] cs = POIUtils.cellStyle(workbook); POIUtils.createHeard(sh, row, cell, cs, title); for (int i = 1; i <= page; i++) { long offset = (i - 1) * pageSize; long rows = pageSize; exprotMap.put("offset", Long.valueOf(offset)); exprotMap.put("rows", Long.valueOf(rows)); // ?? List<AutoRecordData> autoRecordDataList = autoRecordDataMapper.exprot2Excel(exprotMap); if (autoRecordDataList.isEmpty()) continue; for (int rownum = 0; rownum < autoRecordDataList.size(); rownum++) { AutoRecordData autoRecord = autoRecordDataList.get(rownum); String subStation = SubStationConstant.getSubStationByKey(autoRecord.getSubStation()); String licenseDate = DateFormatUtils.format(autoRecord.getLicenseDate(), DateFormatUtils.ymd); String inspectionDate = DateFormatUtils.format(autoRecord.getInspectionDate(), DateFormatUtils.ymd); String insuranceDate = DateFormatUtils.format(autoRecord.gettLInsuranceDate(), DateFormatUtils.ymd); String changeDate = DateFormatUtils.format(autoRecord.getChangeDate(), DateFormatUtils.ymd); String strongInsDate = DateFormatUtils.format(autoRecord.getStrongInsDate(), DateFormatUtils.ymd); // ? ?sheet if (flag > pageSize) { flag = 1; sh = workbook.createSheet(excelName + System.currentTimeMillis()); row = sh.createRow((short) 0); POIUtils.createHeard(sh, row, cell, cs, title); } row = sh.createRow(flag); for (int cellnum = 0; cellnum < title.length; cellnum++) { cell = row.createCell(0); cell.setCellValue(subStation); cell.setCellStyle(cs[1]); cell = row.createCell(1); cell.setCellValue(autoRecord.getDeputyCard()); cell.setCellStyle(cs[1]); cell = row.createCell(2); cell.setCellValue(autoRecord.getCarKind()); cell.setCellStyle(cs[1]); cell = row.createCell(3); cell.setCellValue(autoRecord.getLicenseNo()); cell.setCellStyle(cs[1]); cell = row.createCell(4); cell.setCellValue(autoRecord.getLicense()); cell.setCellStyle(cs[1]); cell = row.createCell(5); cell.setCellValue(licenseDate); cell.setCellStyle(cs[1]); cell = row.createCell(6); cell.setCellValue(autoRecord.getLicenseName()); cell.setCellStyle(cs[1]); cell = row.createCell(7); cell.setCellValue(inspectionDate); cell.setCellStyle(cs[1]); cell = row.createCell(8); cell.setCellValue(autoRecord.getName()); cell.setCellStyle(cs[1]); cell = row.createCell(9); cell.setCellValue(autoRecord.getIdCard()); cell.setCellStyle(cs[1]); cell = row.createCell(10); cell.setCellValue(String.valueOf(autoRecord.getFtReceive())); cell.setCellStyle(cs[1]); cell = row.createCell(11); cell.setCellValue(changeDate); cell.setCellStyle(cs[1]); cell = row.createCell(12); cell.setCellValue(autoRecord.getTelephone()); cell.setCellStyle(cs[1]); cell = row.createCell(13); cell.setCellValue(strongInsDate); cell.setCellStyle(cs[1]); cell = row.createCell(14); cell.setCellValue(String.valueOf(autoRecord.gettLInsurance())); cell.setCellStyle(cs[1]); cell = row.createCell(15); cell.setCellValue(insuranceDate); cell.setCellStyle(cs[1]); cell = row.createCell(16); cell.setCellValue(autoRecord.getPoliceProve()); cell.setCellStyle(cs[1]); cell = row.createCell(17); cell.setCellValue(autoRecord.getHouseholdCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(18); cell.setCellValue(autoRecord.getIdCardCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(19); cell.setCellValue(autoRecord.getLicenseCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(20); cell.setCellValue(autoRecord.getGuaranRespon()); cell.setCellStyle(cs[1]); cell = row.createCell(21); cell.setCellValue(autoRecord.getGuaranIncome()); cell.setCellStyle(cs[1]); cell = row.createCell(22); cell.setCellValue(autoRecord.getGuaranHouseCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(23); cell.setCellValue(autoRecord.getGuaranIDCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(24); cell.setCellValue(autoRecord.getDriLicenseCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(25); cell.setCellValue(autoRecord.getStrongInsCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(26); cell.setCellValue(autoRecord.getCommerInsuCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(27); cell.setCellValue(autoRecord.getCertificate()); cell.setCellStyle(cs[1]); cell = row.createCell(28); cell.setCellValue(String.valueOf(autoRecord.getAgreeDate())); cell.setCellStyle(cs[1]); cell = row.createCell(29); cell.setCellValue(autoRecord.getRentalAgreement()); cell.setCellStyle(cs[1]); cell = row.createCell(30); cell.setCellValue(autoRecord.getStrongInsPrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(31); cell.setCellValue(autoRecord.gettLInsurancePrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(32); cell.setCellValue(autoRecord.getInspectionPrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(33); cell.setCellValue(autoRecord.getChangePrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(34); cell.setCellValue(autoRecord.getStatus()); cell.setCellStyle(cs[1]); } flag++; } } POIUtils.exprot(workbook, response, excelName); }
From source file:com.jshuabo.reportcenter.server.service.automoblie.impl.DefaultBranchLineCarInfoServiceImpl.java
License:Open Source License
@Override public void importToExcel(Map<String, Object> exprotMap, HttpServletResponse response, HttpServletRequest request, String[] title, String excelName) { User user = SecurityContextHolder.getCurrentUser(); if (StringUtils.isEmpty(exprotMap.get("subStation"))) { exprotMap.put("subStation", user.getId()); }/*from ww w. j av a 2 s . c om*/ Map<String, Object> pageData = carInfoMapper.exprotPageData(exprotMap); SXSSFWorkbook workbook = new SXSSFWorkbook(1000); // keep 100 rows in memory, exceeding rows int flag = 1; // int rowCount = 150000; // ?sheet long count = (Long) pageData.get("COUNT"); long pageSize = rowCount; // ?? long page = 1; if (rowCount < count) { if (count % pageSize == 0) { } else { page = count / pageSize + 1; } // } Sheet sh = workbook.createSheet(excelName + System.currentTimeMillis()); Row row = sh.createRow((short) 0); // Cell cell = null; CellStyle[] cs = POIUtils.cellStyle(workbook); POIUtils.createHeard(sh, row, cell, cs, title); for (int i = 1; i <= page; i++) { long offset = (i - 1) * pageSize; long rows = pageSize; exprotMap.put("offset", Long.valueOf(offset)); exprotMap.put("rows", Long.valueOf(rows)); // ?? List<BranchLineCarInfo> autoRecordDataList = carInfoMapper.exprot2Excel(exprotMap); if (autoRecordDataList.isEmpty()) continue; for (int rownum = 0; rownum < autoRecordDataList.size(); rownum++) { BranchLineCarInfo branchLineCarInfo = autoRecordDataList.get(rownum); String subStation = branchLineCarInfo.getExtendProp3(); String licenseDate = DateFormatUtils.format(branchLineCarInfo.getLicenseDate(), DateFormatUtils.ymd); String inspectionDate = DateFormatUtils.format(branchLineCarInfo.getInspectionDate(), DateFormatUtils.ymd); String insuranceDate = DateFormatUtils.format(branchLineCarInfo.getTlInsuranceDate(), DateFormatUtils.ymd); String changeDate = DateFormatUtils.format(branchLineCarInfo.getChangeDate(), DateFormatUtils.ymd); String strongInsDate = DateFormatUtils.format(branchLineCarInfo.getStrongInsdate(), DateFormatUtils.ymd); String agreeDate = DateFormatUtils.format(branchLineCarInfo.getAgreeDate(), DateFormatUtils.ymd); // ? ?sheet if (flag > pageSize) { flag = 1; sh = workbook.createSheet(excelName + System.currentTimeMillis()); row = sh.createRow((short) 0); POIUtils.createHeard(sh, row, cell, cs, title); } row = sh.createRow(flag); for (int cellnum = 0; cellnum < title.length; cellnum++) { cell = row.createCell(0); cell.setCellValue(subStation); cell.setCellStyle(cs[1]); cell = row.createCell(1); cell.setCellValue(branchLineCarInfo.getDeputyCard()); cell.setCellStyle(cs[1]); cell = row.createCell(2); cell.setCellValue(branchLineCarInfo.getCarKind()); cell.setCellStyle(cs[1]); cell = row.createCell(3); cell.setCellValue(branchLineCarInfo.getLicenseNo()); cell.setCellStyle(cs[1]); cell = row.createCell(4); cell.setCellValue(branchLineCarInfo.getLicense()); cell.setCellStyle(cs[1]); cell = row.createCell(5); cell.setCellValue(licenseDate); cell.setCellStyle(cs[1]); cell = row.createCell(6); cell.setCellValue(branchLineCarInfo.getLicenseName()); cell.setCellStyle(cs[1]); cell = row.createCell(7); cell.setCellValue(inspectionDate); cell.setCellStyle(cs[1]); cell = row.createCell(8); cell.setCellValue(branchLineCarInfo.getName()); cell.setCellStyle(cs[1]); cell = row.createCell(9); cell.setCellValue(branchLineCarInfo.getIdCard()); cell.setCellStyle(cs[1]); cell = row.createCell(10); cell.setCellValue(String.valueOf(branchLineCarInfo.getFtReceive())); cell.setCellStyle(cs[1]); cell = row.createCell(11); cell.setCellValue(changeDate); cell.setCellStyle(cs[1]); cell = row.createCell(12); cell.setCellValue(branchLineCarInfo.getTelephone()); cell.setCellStyle(cs[1]); cell = row.createCell(13); cell.setCellValue(strongInsDate); cell.setCellStyle(cs[1]); cell = row.createCell(14); cell.setCellValue(StringUtils.isEmpty(branchLineCarInfo.getTlInsurance()) ? 0D : branchLineCarInfo.getTlInsurance()); cell.setCellStyle(cs[1]); cell = row.createCell(15); cell.setCellValue(insuranceDate); cell.setCellStyle(cs[1]); cell = row.createCell(16); cell.setCellValue(branchLineCarInfo.getPoliceProve()); cell.setCellStyle(cs[1]); cell = row.createCell(17); cell.setCellValue(branchLineCarInfo.getHouseholdCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(18); cell.setCellValue(branchLineCarInfo.getIdcardCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(19); cell.setCellValue(branchLineCarInfo.getLicenseCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(20); cell.setCellValue(branchLineCarInfo.getGuaranRespon()); cell.setCellStyle(cs[1]); cell = row.createCell(21); cell.setCellValue(branchLineCarInfo.getGuaranIncome()); cell.setCellStyle(cs[1]); cell = row.createCell(22); cell.setCellValue(branchLineCarInfo.getGuaranhouseCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(23); cell.setCellValue(branchLineCarInfo.getGuaranidCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(24); cell.setCellValue(branchLineCarInfo.getDrilicenseCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(25); cell.setCellValue(branchLineCarInfo.getStronginsCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(26); cell.setCellValue(branchLineCarInfo.getCommerinsuCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(27); cell.setCellValue(branchLineCarInfo.getCertificate()); cell.setCellStyle(cs[1]); cell = row.createCell(28); cell.setCellValue(agreeDate); cell.setCellStyle(cs[1]); cell = row.createCell(29); cell.setCellValue(branchLineCarInfo.getRentalAgreement()); cell.setCellStyle(cs[1]); cell = row.createCell(30); cell.setCellValue(branchLineCarInfo.getStronginsPrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(31); cell.setCellValue(branchLineCarInfo.getTlinsurancePrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(32); cell.setCellValue(branchLineCarInfo.getInspectionPrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(33); cell.setCellValue(branchLineCarInfo.getChangePrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(34); cell.setCellValue(branchLineCarInfo.getStatus()); cell.setCellStyle(cs[1]); } flag++; } } POIUtils.exprot(workbook, response, excelName); }
From source file:com.jshuabo.reportcenter.server.service.automoblie.impl.DefaultBranchLineDrawoutRecordServiceImpl.java
@Override public void importToExcel(Map<String, Object> exprotMap, HttpServletResponse response, HttpServletRequest request, String[] title, String excelName) { User user = SecurityContextHolder.getCurrentUser(); if (StringUtils.isEmpty(exprotMap.get("subStation"))) { exprotMap.put("subStation", user.getId()); }/*from w w w .j ava2s. c o m*/ Map<String, Object> pageData = drawoutRecordDataMapper.exprotPageData(exprotMap); SXSSFWorkbook workbook = new SXSSFWorkbook(1000); // keep 100 rows in memory, exceeding rows int flag = 1; // int rowCount = 150000; // ?sheet long count = (Long) pageData.get("COUNT"); long pageSize = rowCount; // ?? long page = 1; if (rowCount < count) { if (count % pageSize == 0) { } else { page = count / pageSize + 1; } // } Sheet sh = workbook.createSheet(excelName + System.currentTimeMillis()); Row row = sh.createRow((short) 0); // Cell cell = null; CellStyle[] cs = POIUtils.cellStyle(workbook); POIUtils.createHeard(sh, row, cell, cs, title); for (int i = 1; i <= page; i++) { long offset = (i - 1) * pageSize; long rows = pageSize; exprotMap.put("offset", Long.valueOf(offset)); exprotMap.put("rows", Long.valueOf(rows)); // ?? List<BranchLineDrawoutRecord> drawoutRecordDataList = drawoutRecordDataMapper.exprot2Excel(exprotMap); if (drawoutRecordDataList.isEmpty()) continue; for (int rownum = 0; rownum < drawoutRecordDataList.size(); rownum++) { BranchLineDrawoutRecord bdr = drawoutRecordDataList.get(rownum); String data = DateFormatUtils.format(bdr.getDate(), DateFormatUtils.ymd); String subStation = bdr.getExtendProp3(); // ? ?sheet if (flag > pageSize) { flag = 1; sh = workbook.createSheet(excelName + System.currentTimeMillis()); row = sh.createRow((short) 0); POIUtils.createHeard(sh, row, cell, cs, title); } row = sh.createRow(flag); for (int cellnum = 0; cellnum < title.length; cellnum++) { cell = row.createCell(0); cell.setCellValue(subStation); cell.setCellStyle(cs[1]); cell = row.createCell(1); cell.setCellValue(data); cell.setCellStyle(cs[1]); cell = row.createCell(2); cell.setCellValue(bdr.getLicenseNo()); cell.setCellStyle(cs[1]); cell = row.createCell(3); cell.setCellValue(bdr.getDriver()); cell.setCellStyle(cs[1]); cell = row.createCell(4); cell.setCellValue(bdr.getLine()); cell.setCellStyle(cs[1]); cell = row.createCell(5); cell.setCellValue(bdr.getGpsNo()); cell.setCellStyle(cs[1]); cell = row.createCell(6); cell.setCellValue(bdr.getStartTime()); cell.setCellStyle(cs[1]); cell = row.createCell(7); cell.setCellValue(bdr.getStartMileage()); cell.setCellStyle(cs[1]); cell = row.createCell(8); cell.setCellValue(bdr.getStopTime()); cell.setCellStyle(cs[1]); cell = row.createCell(9); cell.setCellValue(bdr.getStopMileage()); cell.setCellStyle(cs[1]); cell = row.createCell(10); cell.setCellValue(bdr.getMileage()); cell.setCellStyle(cs[1]); cell = row.createCell(11); String temp = bdr.getExtendProp2(); cell.setCellValue(StringUtils.isEmpty(temp) ? 0D : Double.valueOf(temp)); cell.setCellStyle(cs[1]); cell = row.createCell(12); cell.setCellValue(bdr.getTicketQuantity()); cell.setCellStyle(cs[1]); cell = row.createCell(13); cell.setCellValue(bdr.getHallQuantity()); cell.setCellStyle(cs[1]); cell = row.createCell(14); cell.setCellValue(bdr.getPieQuantity()); cell.setCellStyle(cs[1]); cell = row.createCell(15); cell.setCellValue(bdr.getPcsQuantity()); cell.setCellStyle(cs[1]); cell = row.createCell(16); cell.setCellValue(bdr.getFuelPrice()); cell.setCellStyle(cs[1]); cell = row.createCell(17); cell.setCellValue(bdr.getFuelCosts()); cell.setCellStyle(cs[1]); cell = row.createCell(18); cell.setCellValue(bdr.getDay()); cell.setCellStyle(cs[1]); cell = row.createCell(19); cell.setCellValue(bdr.getRentalFee()); cell.setCellStyle(cs[1]); cell = row.createCell(20); cell.setCellValue(bdr.getParkingFee()); cell.setCellStyle(cs[1]); cell = row.createCell(21); cell.setCellValue(bdr.getAward()); cell.setCellStyle(cs[1]); cell = row.createCell(22); cell.setCellValue(bdr.getIsReim()); cell.setCellStyle(cs[1]); cell = row.createCell(23); cell.setCellValue(bdr.getNoDelivery()); cell.setCellStyle(cs[1]); cell = row.createCell(24); cell.setCellValue(bdr.getRefusal()); cell.setCellStyle(cs[1]); cell = row.createCell(25); cell.setCellValue(bdr.getVoteSign()); cell.setCellStyle(cs[1]); cell = row.createCell(26); cell.setCellValue(bdr.getRemarks()); cell.setCellStyle(cs[1]); cell = row.createCell(27); cell.setCellValue(bdr.getExtendProp1()); cell.setCellStyle(cs[1]); } flag++; } } POIUtils.exprot(workbook, response, excelName); }
From source file:com.luna.showcase.excel.service.ExcelDataService.java
License:Apache License
/** * ???/* w ww.j a va2s.com*/ * 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(); } }