List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet setMargin
@Override public void setMargin(short margin, double size)
From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java
public void printTbFixEntrustTemplate(OutputStream os, String tpl, Long tbFixEntrustId) { /*// w w w. jav a2s .co m * Workbook wb = null; * * WritableWorkbook wwb = null; * * WritableSheet ws = null; * * try { * * wb = Workbook.getWorkbook(this.getClass().getResourceAsStream(tpl)); * * wwb = Workbook.createWorkbook(os, wb); * * ws = wwb.getSheet(0); * * WritableCellFormat wcf = new WritableCellFormat(); * * wcf.setVerticalAlignment(VerticalAlignment.CENTRE); * * wcf.setAlignment(Alignment.CENTRE); * * wcf.setWrap(true); * * TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); * * TbCustomer tbCustomer = * tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); * * TbCarInfo tbCarInfo = * tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); * * Label label = null; * * label = new Label(0, 10, tbFixEntrust.getEntrustCode(), wcf); * * ws.addCell(label); * * label = new Label(8, 10, tbCarInfo.getPurchaseDate()== null ? "" : * CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), * "yyyy-MM-dd"), wcf); * * ws.addCell(label); * * label = new Label(14, 10, tbFixEntrust.getTmUser().getUserRealName(), * wcf); * * ws.addCell(label); * * label = new Label(20, 10, tbCarInfo.getLicenseCode(), wcf); * * ws.addCell(label); * * label = new Label(27, 10, * tbCarInfo.getTmCarModelType().getModelName(), wcf); * * ws.addCell(label); * * label = new Label(32, 10, tbFixEntrust.getEnterStationKilo() == null * ? "" : tbFixEntrust.getEnterStationKilo().toString(), wcf); * * ws.addCell(label); * * label = new Label(41, 10, tbCarInfo.getColor() == null ? "" : * tbCarInfo.getColor().toString(), wcf); * * ws.addCell(label); * * label = new Label(45, 10, tbFixEntrust.getFixDate() == null ? "" : * CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), * "yyyy-MM-dd HH:mm:ss"), wcf); * * ws.addCell(label); * * label = new Label(0, 15, tbCustomer.getCustomerName() == null ? "" : * tbCustomer.getCustomerName(), wcf); * * ws.addCell(label); * * label = new Label(8, 15, tbCustomer.getTelephone() == null ? "" : * tbCustomer.getTelephone(), wcf); * * ws.addCell(label); * * label = new Label(14, 15, tbCustomer.getPhone() == null ? "" : * tbCustomer.getPhone(), wcf); * * ws.addCell(label); * * label = new Label(20, 15, tbCarInfo.getChassisCode() == null ? "" : * tbCarInfo.getChassisCode(), wcf); * * ws.addCell(label); * * label = new Label(32, 15, tbCarInfo.getEngineCode() == null ? "" : * tbCarInfo.getEngineCode(),wcf); * * ws.addCell(label); * * label = new Label(45, 15, tbFixEntrust.getEstimateDate() == null ? "" * : CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), * "yyyy-MM-dd HH:mm:ss"),wcf); * * ws.addCell(label); * * label = new Label(8, 18, tbCustomer.getCustomerName() == null ? "" : * tbCustomer.getCustomerName(), wcf); * * ws.addCell(label); * * label = new Label(0, 22, tbCustomer.getAddress() == null ? "" : * tbCustomer.getAddress(), wcf); * * ws.addCell(label); * * label = new Label(8, 25, tbCustomer.getZipCode() == null ? "" : * tbCustomer.getZipCode(), wcf); * * ws.addCell(label); * * label = new Label(20, 20, (tbFixEntrust.getWrongDescribe() == * null?"":tbFixEntrust.getWrongDescribe()) +";" + * (tbFixEntrust.getBeforeFixState * ()==null?"":tbFixEntrust.getBeforeFixState()) + ";" + * (tbFixEntrust.getCheckResult * ()==null?"":tbFixEntrust.getCheckResult()) + ";" + * (tbFixEntrust.getRemark()==null?"":tbFixEntrust.getRemark()), wcf); * * ws.addCell(label); * * wwb.write(); * * } catch (BiffException e) { * * e.printStackTrace(); } catch (IOException e) { * * e.printStackTrace(); } catch (RowsExceededException e) { // TODO * Auto-generated catch block e.printStackTrace(); } catch * (WriteException e) { // TODO Auto-generated catch block * e.printStackTrace(); } finally { * * if (null != wb) { * * wb.close(); * * } * * if (null != wwb) { * * try { wwb.close(); } catch (WriteException e) { * * e.printStackTrace(); } catch (IOException e) { * * e.printStackTrace(); } } * * } */ try { TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); TbCustomer tbCustomer = tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); TbCarInfo tbCarInfo = tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); List<TbFixEntrustContent> tbFixEntrustContentList = tbFixEntrustContentService .findTbFixEnTrustContentListByTbFixEntrustId(tbFixEntrustId); /* * List<TbMaintainPartContent> maintainList = * tbMaintainPartContentService * .getViewEntrustMaintianContent(tbFixEntrustId); * * * List<TmStockOutDetVo> solePartList = * tmStockOutService.getSellByEntrustCode * (tbFixEntrust.getEntrustCode()); */ /** * ?? */ List<TbMaintianVo> maintianvos = tbMaintainPartContentService .getTbMaintianDetailVosByEntrustId(tbFixEntrust.getId(), Constants.BALANCE_ALL); /** * ? */ List<TmStockOutDetVo> tmStockOutDetVos = tmStockOutService .getSellDetailByEntrustCode(tbFixEntrust.getEntrustCode(), Constants.BALANCE_ALL); /** * ?? */ List<TbMaintianVo> partAll = new ArrayList<TbMaintianVo>(); if (null != maintianvos && maintianvos.size() > 0) { for (TbMaintianVo tbMaintianVo : maintianvos) { partAll.add(tbMaintianVo); } } if (null != tmStockOutDetVos && tmStockOutDetVos.size() > 0) { for (TmStockOutDetVo tmStockOutDetVo : tmStockOutDetVos) { TbMaintianVo tbMaintianVo = new TbMaintianVo(); tbMaintianVo.setPartId(tmStockOutDetVo.getPartinfoId()); tbMaintianVo.setHouseName(tmStockOutDetVo.getHouseName()); tbMaintianVo.setPartCode(tmStockOutDetVo.getPartCode()); tbMaintianVo.setPartName(tmStockOutDetVo.getPartName()); tbMaintianVo.setUnitName(tmStockOutDetVo.getUnitName()); tbMaintianVo.setPrice(tmStockOutDetVo.getPrice()); tbMaintianVo.setPartQuantity(tmStockOutDetVo.getQuantity()); tbMaintianVo.setTotal(tmStockOutDetVo.getTotal()); tbMaintianVo.setIsFree(tmStockOutDetVo.getIsFree()); tbMaintianVo.setProjectType(tmStockOutDetVo.getProjectType()); tbMaintianVo.setZl(tmStockOutDetVo.getZl()); tbMaintianVo.setXmlx(tmStockOutDetVo.getXmlx()); partAll.add(tbMaintianVo); } } int fixSize = (tbFixEntrustContentList == null ? 0 : tbFixEntrustContentList.size()); int maintainSize = (maintianvos == null ? 0 : maintianvos.size()); int solePartSize = (tmStockOutDetVos == null ? 0 : tmStockOutDetVos.size()); int partAllSize = (partAll == null ? 0 : partAll.size()); HSSFWorkbook workbook = new HSSFWorkbook(this.getClass().getResourceAsStream(tpl)); HSSFSheet sheet = workbook.getSheetAt(0); sheet.setMargin(HSSFSheet.LeftMargin, (double) 0.5); sheet.setMargin(HSSFSheet.RightMargin, (double) 0.5); HSSFCellStyle style = workbook.createCellStyle(); style.setWrapText(true); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontName(""); font.setFontHeightInPoints((short) 9); style.setFont(font); HSSFRow row = null; HSSFCell cell = null; ByteArrayOutputStream byteArrayOutImgLion = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutDBZF = new ByteArrayOutputStream(); BufferedImage bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/lion.png")); BufferedImage bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/dfbz.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFClientAnchor anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 48, 0, (short) 53, 7); HSSFClientAnchor anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 200, (short) 0, 0, (short) 8, 7); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); row = sheet.getRow(10); cell = row.getCell(0); String entrustCode = tbFixEntrust.getEntrustCode(); String[] es = entrustCode.split("-"); String newCode = "RO" + es[0].substring(2, 6) + es[1]; // cell.setCellValue(tbFixEntrust.getEntrustCode()); cell.setCellValue(newCode); row = sheet.getRow(10); cell = row.getCell(8); cell.setCellValue(tbCarInfo.getPurchaseDate() == null ? "" : CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), "yyyy-MM-dd")); row = sheet.getRow(10); cell = row.getCell(14); cell.setCellValue( tbFixEntrust.getTmUser().getUserRealName() == null ? tbFixEntrust.getTmUser().getUserName() : tbFixEntrust.getTmUser().getUserRealName()); row = sheet.getRow(10); cell = row.getCell(19); cell.setCellValue(tbCarInfo.getLicenseCode()); row = sheet.getRow(10); cell = row.getCell(27); cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getTmCarModelType().getModelName()); row = sheet.getRow(10); cell = row.getCell(32); cell.setCellValue( tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo().toString()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString() + " Km"); row = sheet.getRow(10); cell = row.getCell(41); cell.setCellValue(tbCarInfo.getColor() == null ? "" : tbCarInfo.getColor().toString()); row = sheet.getRow(10); cell = row.getCell(45); cell.setCellValue(tbFixEntrust.getFixDate() == null ? "" : CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), Constants.TIMEFORMATOFMINUTE)); row = sheet.getRow(15); cell = row.getCell(0); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getContractPerson()); row = sheet.getRow(15); cell = row.getCell(8); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(15); cell = row.getCell(14); cell.setCellValue(tbCustomer.getPhone() == null ? "" : tbCustomer.getPhone()); row = sheet.getRow(15); cell = row.getCell(20); cell.setCellValue(tbCarInfo.getChassisCode() == null ? "" : tbCarInfo.getChassisCode()); row = sheet.getRow(15); cell = row.getCell(32); // cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getEngineCode() == null ? "" : tbCarInfo.getEngineCode()); row = sheet.getRow(15); cell = row.getCell(45); // cell.setCellStyle(style); cell.setCellValue(tbFixEntrust.getEstimateDate() == null ? "" : CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), Constants.TIMEFORMATOFMINUTE)); row = sheet.getRow(18); cell = row.getCell(8); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getCustomerName()); row = sheet.getRow(20); cell = row.getCell(8); cell.setCellStyle(style); cell.setCellValue(tbCustomer.getAddress() == null ? "" : tbCustomer.getAddress()); row = sheet.getRow(25); cell = row.getCell(8); cell.setCellValue(tbCustomer.getZipCode() == null ? "" : tbCustomer.getZipCode()); row = sheet.getRow(20); cell = row.getCell(23); cell.setCellStyle(style); cell.setCellValue((tbFixEntrust.getWrongDescribe() == null || "".equals(tbFixEntrust.getWrongDescribe()) ? "" : tbFixEntrust.getWrongDescribe() + ";") + (tbFixEntrust.getBeforeFixState() == null || "".equals(tbFixEntrust.getBeforeFixState()) ? "" : tbFixEntrust.getBeforeFixState() + ";")); Double fixCount = tbFixEntrustContentService.countTbFixEnTrustContentByTbFixEntrustId(tbFixEntrustId); row = sheet.getRow(70); cell = row.getCell(32); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(fixCount).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); row = sheet.getRow(70); cell = row.getCell(48); cell.setCellStyle(style); cell.setCellValue("0.00"); BigDecimal partPriceAll = new BigDecimal("0.00"); if (partAllSize > 0) { for (int i = 0; i < partAllSize; i++) { TbMaintianVo tbMaintianVo = partAll.get(i); BigDecimal total = new BigDecimal(tbMaintianVo.getPrice()) .multiply(new BigDecimal(tbMaintianVo.getPartQuantity())); partPriceAll = partPriceAll.add(total); } } row = sheet.getRow(73); cell = row.getCell(33); cell.setCellStyle(style); cell.setCellValue(partPriceAll.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); BigDecimal total = new BigDecimal(fixCount).add(partPriceAll).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); row = sheet.getRow(76); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(total.toString()); int page = 1; if (fixSize / 5 >= (maintainSize + solePartSize) / 13) { page = fixSize / 5; } else { page = (maintainSize + solePartSize) / 13; } for (int i = 0; i < page; i++) { int p = 0; int k = 0; HSSFSheet sheetClone = workbook.cloneSheet(0); byteArrayOutImgLion = new ByteArrayOutputStream(); byteArrayOutDBZF = new ByteArrayOutputStream(); bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/lion.png")); bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/dfbz.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); patriarch = sheetClone.createDrawingPatriarch(); anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 48, 0, (short) 53, 7); anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 200, (short) 0, 0, (short) 8, 7); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); if (fixSize > 5) { int printFixSize = (fixSize > (i + 2) * 5 ? (i + 2) * 5 : fixSize); for (int j = 5 * (i + 1); j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; } } } row = sheetClone.getRow(31 + p * 6); cell = row.getCell(0); cell.setCellStyle(style); cell.setCellValue(content.getStationCode() + " " + content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(content.getXmlx() == null ? "" : content.getXmlx()); cell = row.getCell(26); cell.setCellStyle(style); cell.setCellValue(fixPersons); p++; } } if (partAllSize > 13) { int prinPartSize = (partAllSize > (i + 2) * 13 ? (i + 2) * 13 : partAllSize); for (int j = 13 * (i + 1); j < prinPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheetClone.getRow(31 + k * 3); cell = row.getCell(32); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(t.getPartQuantity()); cell = row.getCell(44); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); k++; } } } if (fixSize > 0) { int printFixSize = (fixSize > 5 ? 5 : fixSize); for (int j = 0; j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; } } } row = sheet.getRow(31 + j * 6); cell = row.getCell(0); cell.setCellStyle(style); cell.setCellValue(content.getStationCode() + " " + content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(content.getXmlx() == null ? "" : content.getXmlx()); cell = row.getCell(26); cell.setCellStyle(style); cell.setCellValue(fixPersons); } } if (partAllSize > 0) { int printPartSize = (partAllSize > 13 ? 13 : partAllSize); for (int j = 0; j < printPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheet.getRow(31 + j * 3); cell = row.getCell(32); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(t.getPartQuantity()); cell = row.getCell(44); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } } workbook.write(os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.square.core.util.poi.DocumentXls.java
License:Open Source License
/** Cree une page. */ private HSSFSheet creerPage() { final HSSFSheet page = classeur.createSheet(); page.setMargin(HSSFSheet.LeftMargin, LARGEUR_MARGE); page.setMargin(HSSFSheet.RightMargin, LARGEUR_MARGE); row = 0;// w w w . j av a 2 s . c o m if (entetesWidth != null) { // Dfinition de la largeur des colonnes int col = 0; for (Integer enteteWidth : entetesWidth) { if (enteteWidth != null) { page.setColumnWidth(col, enteteWidth); } col++; } } final HSSFCellStyle styleEntete = classeur.createCellStyle(); final HSSFFont policeEntete = classeur.createFont(); policeEntete.setFontHeightInPoints(ENTETE_FONT_HEIGHT); policeEntete.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); styleEntete.setFont(policeEntete); // Affichage des titres de colonnes ajouterLigne(entetes, styleEntete); return page; }
From source file:org.adempiere.print.export.PrintDataExcelExporter.java
License:Open Source License
@Override protected void formatPage(HSSFSheet sheet) { super.formatPage(sheet); MPrintPaper paper = MPrintPaper.get(this.m_printFormat.getAD_PrintPaper_ID()); ///* w w w . ja v a 2s .c om*/ // Set paper size: short paperSize = -1; MediaSizeName mediaSizeName = paper.getMediaSize().getMediaSizeName(); if (MediaSizeName.NA_LETTER.equals(mediaSizeName)) { paperSize = HSSFPrintSetup.LETTER_PAPERSIZE; } else if (MediaSizeName.NA_LEGAL.equals(mediaSizeName)) { paperSize = HSSFPrintSetup.LEGAL_PAPERSIZE; } else if (MediaSizeName.EXECUTIVE.equals(mediaSizeName)) { paperSize = HSSFPrintSetup.EXECUTIVE_PAPERSIZE; } else if (MediaSizeName.ISO_A4.equals(mediaSizeName)) { paperSize = HSSFPrintSetup.A4_PAPERSIZE; } else if (MediaSizeName.ISO_A5.equals(mediaSizeName)) { paperSize = HSSFPrintSetup.A5_PAPERSIZE; } else if (MediaSizeName.NA_NUMBER_10_ENVELOPE.equals(mediaSizeName)) { paperSize = HSSFPrintSetup.ENVELOPE_10_PAPERSIZE; } // else if (MediaSizeName..equals(mediaSizeName)) { // paperSize = HSSFPrintSetup.ENVELOPE_DL_PAPERSIZE; // } // else if (MediaSizeName..equals(mediaSizeName)) { // paperSize = HSSFPrintSetup.ENVELOPE_CS_PAPERSIZE; // } else if (MediaSizeName.MONARCH_ENVELOPE.equals(mediaSizeName)) { paperSize = HSSFPrintSetup.ENVELOPE_MONARCH_PAPERSIZE; } if (paperSize != -1) { sheet.getPrintSetup().setPaperSize(paperSize); } // // Set Landscape/Portrait: sheet.getPrintSetup().setLandscape(paper.isLandscape()); // // Set Paper Margin: sheet.setMargin(HSSFSheet.TopMargin, ((double) paper.getMarginTop()) / 72); sheet.setMargin(HSSFSheet.RightMargin, ((double) paper.getMarginRight()) / 72); sheet.setMargin(HSSFSheet.LeftMargin, ((double) paper.getMarginLeft()) / 72); sheet.setMargin(HSSFSheet.BottomMargin, ((double) paper.getMarginBottom()) / 72); // }
From source file:org.eclipse.scada.ae.ui.views.export.excel.impl.ExportEventsImpl.java
License:Open Source License
private HSSFSheet createSheet(final List<Event> events, final HSSFWorkbook workbook, final List<Field> columns) { final HSSFSheet sheet = workbook.createSheet(Messages.ExportImpl_ExcelSheet_Name); final HSSFHeader header = sheet.getHeader(); header.setLeft(Messages.ExportImpl_ExcelSheet_Header); header.setRight(HeaderFooter.date() + " " + HeaderFooter.time());//$NON-NLS-1$ final HSSFFooter footer = sheet.getFooter(); footer.setLeft(String.format(Messages.ExportImpl_ExcelSheet_Footer_1, events.size())); footer.setRight(Messages.ExportImpl_ExcelSheet_Footer_2 + HeaderFooter.page() + Messages.ExportImpl_ExcelSheet_Footer_3 + HeaderFooter.numPages()); makeHeader(columns, sheet);//from ww w . ja va 2 s. c o m final HSSFPrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); printSetup.setFitWidth((short) 1); printSetup.setFitHeight((short) 0); printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); sheet.setAutoFilter(new CellRangeAddress(0, 0, 0, columns.size() - 1)); sheet.createFreezePane(0, 1); sheet.setFitToPage(true); sheet.setAutobreaks(true); printSetup.setFooterMargin(0.25); sheet.setMargin(Sheet.LeftMargin, 0.25); sheet.setMargin(Sheet.RightMargin, 0.25); sheet.setMargin(Sheet.TopMargin, 0.25); sheet.setMargin(Sheet.BottomMargin, 0.5); return sheet; }