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 ); 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; }
protected void createHeaderFooter(final HSSFSheet sheet) { // Sheet Header HSSFHeader header = sheet.getHeader(); header.setRight(HSSFHeader.page() + " / " + HSSFHeader.numPages()); // Sheet Footer HSSFFooter footer = sheet.getFooter(); footer.setLeft(Adempiere.getBrandCopyright()); footer.setCenter(Env.getHeader(getCtx(), 0)); Timestamp now = new Timestamp(System.currentTimeMillis()); footer.setRight(DisplayType.getDateFormat(DisplayType.DateTime, getLanguage()).format(now)); }
public void exportExcel(OutputStream os) throws IOException { sheet.setGridsPrinted(true); HSSFFooter footer = sheet.getFooter(); footer.setRight("Page " + HSSFFooter.page() + " of " + HSSFFooter.numPages()); book.write(os); }
@Override protected void updateSheet(JRPrintElement element) { JRXlsMetadataExporterNature xlsNature = (JRXlsMetadataExporterNature)nature; configureDefinedNames(xlsNature, element); updatePageMargin(xlsNature.getPrintPageTopMargin(element), Sheet.TopMargin); updatePageMargin(xlsNature.getPrintPageLeftMargin(element), Sheet.LeftMargin); updatePageMargin(xlsNature.getPrintPageBottomMargin(element), Sheet.BottomMargin); updatePageMargin(xlsNature.getPrintPageRightMargin(element), Sheet.RightMargin); updateHeaderFooterMargin(xlsNature.getPrintHeaderMargin(element), true); updateHeaderFooterMargin(xlsNature.getPrintFooterMargin(element), false); HSSFHeader header = sheet.getHeader(); String sheetHeaderLeft = xlsNature.getSheetHeaderLeft(element); if(sheetHeaderLeft != null) { header.setLeft(sheetHeaderLeft); } String sheetHeaderCenter = xlsNature.getSheetHeaderCenter(element); if(sheetHeaderCenter != null) { header.setCenter(sheetHeaderCenter); } String sheetHeaderRight = xlsNature.getSheetHeaderRight(element); if(sheetHeaderRight != null) { header.setRight(sheetHeaderRight); } HSSFFooter footer = sheet.getFooter(); String sheetFooterLeft = xlsNature.getSheetFooterLeft(element); if(sheetFooterLeft != null) { footer.setLeft(sheetFooterLeft); } String sheetFooterCenter = xlsNature.getSheetFooterCenter(element); if(sheetFooterCenter != null) { footer.setCenter(sheetFooterCenter); } String sheetFooterRight = xlsNature.getSheetFooterRight(element); if(sheetFooterRight != null) { footer.setRight(sheetFooterRight); } }
/** * [Flow #-4] 엑셀 문서 속성 수정 : 엑셀 파일 문서의 속성(Header, Footer)을 수정함 */ @Test public void testModifyDocAttribute() throws Exception { try { log.debug("testModifyDocAttribute start...."); StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testModifyDocAttribute.xls"); if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); log.debug("Delete file...." + sb.toString()); } HSSFWorkbook wbTmp = new HSSFWorkbook(); wbTmp.createSheet(); // 엑셀 파일 생성 excelService.createWorkbook(wbTmp, sb.toString()); // 엑셀 파일 로드 HSSFWorkbook wb = excelService.loadWorkbook(sb.toString()); log.debug("testModifyCellContents after loadWorkbook...."); HSSFSheet sheet = wb.createSheet("doc test sheet"); HSSFRow row = sheet.createRow(1); HSSFCell cell = row.createCell(1); cell.setCellValue(new HSSFRichTextString("Header/Footer Test")); // Header HSSFHeader header = sheet.getHeader(); header.setCenter("Center Header"); header.setLeft("Left Header"); header.setRight(HSSFHeader.font("Stencil-Normal", "Italic") + HSSFHeader.fontSize((short) 16) + "Right Stencil-Normal Italic font and size 16"); // Footer HSSFFooter footer = sheet.getFooter(); footer.setCenter(HSSFHeader.font("Fixedsys", "Normal") + HSSFHeader.fontSize((short) 12) + "- 1 -"); log.debug("Style is ... " + HSSFHeader.font("Fixedsys", "Normal") + HSSFHeader.fontSize((short) 12) + "- 1 -"); footer.setLeft("Left Footer"); footer.setRight("Right Footer"); // 엑셀 파일 저장 FileOutputStream out = new FileOutputStream(sb.toString()); wb.write(out); out.close(); assertTrue(EgovFileUtil.isExistsFile(sb.toString())); ////////////////////////////////////////////////////////////////////////// // 검증 HSSFWorkbook wbT = excelService.loadWorkbook(sb.toString()); HSSFSheet sheetT = wbT.getSheet("doc test sheet"); HSSFHeader headerT = sheetT.getHeader(); assertEquals("Center Header", headerT.getCenter()); assertEquals("Left Header", headerT.getLeft()); assertEquals(HSSFHeader.font("Stencil-Normal", "Italic") + HSSFHeader.fontSize((short) 16) + "Right Stencil-Normal Italic font and size 16", headerT.getRight()); HSSFFooter footerT = sheetT.getFooter(); assertEquals("Right Footer", footerT.getRight()); assertEquals("Left Footer", footerT.getLeft()); assertEquals(HSSFHeader.font("Fixedsys", "Normal") + HSSFHeader.fontSize((short) 12) + "- 1 -", footerT.getCenter()); } catch (Exception e) { log.error(e.toString()); throw new Exception(e); } finally { log.debug("testModifyDocAttribute end...."); } }