public static void main(String[] args) throws Exception { String dataPath = "src/featurescomparison/workingwithworksheets/headerandfooter/data/"; Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("new sheet"); Header header = sheet.getHeader(); header.setCenter("Center Header"); header.setLeft("Left Header"); header.setRight(HSSFHeader.font("Stencil-Normal", "Italic") + HSSFHeader.fontSize((short) 16) + "Right w/ Stencil-Normal Italic font and size 16"); FileOutputStream fileOut = new FileOutputStream(dataPath + "ApacheHeaderFooter_Out.xls"); wb.write(fileOut); fileOut.close(); System.out.println("Aspose Header Footer Created."); }
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)); }
private void createSheetTitle(HSSFSheet sheet,HSSFCellStyle style1,HSSFCellStyle style2,String documentNumber,String title){ HSSFRow row = sheet.createRow(0); row.setHeightInPoints(30); HSSFCell cell1 = row.createCell(0); cell1.setCellValue(title); cell1.setCellStyle(style1); sheet.addMergedRegion(new CellRangeAddress(0,(short)0,0,(short)6)); row = sheet.createRow(1); HSSFCell[] cell = new HSSFCell[7]; for(int i = 0;i < 7;i++){ cell[i] = row.createCell(i); cell[i].setCellStyle(style2); } HSSFHeader header = sheet.getHeader(); header.setRight("�� " + HSSFHeader.page() + " ҳ"); cell[0].setCellValue("����"); cell[1].setCellValue(documentNumber); //cell[5].setCellValue("��" + header.page() + "ҳ"); sheet.addMergedRegion(new CellRangeAddress(1,1,1,4)); // sheet.addMergedRegion(new CellRangeAddress(1,1,5,6)); }
@SuppressWarnings("deprecation") public void createTableHeader(String[] tableHeader) { HSSFHeader header = sheet.getHeader(); header.setCenter("人员权限信息"); // HSSFRow headerRow = sheet.createRow((short) 0); for (int i = 0; i < tableHeader.length; i++) { HSSFCell headerCell = headerRow.createCell((short) i); headerCell.setCellType(HSSFCell.CELL_TYPE_STRING); /*headerCell.setEncoding(HSSFCell.ENCODING_UTF_16);*/ //removed by zhuqingxiang headerCell.setCellValue(tableHeader[i]); } }
@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...."); } }