/** * シートのコピーを作成します。 * @param sheets コピーを作成するシートの数。 * @throws Exception 例外。 */ protected void addSheets(final int sheets) throws Exception { this.workbook = this.getTamplate(); for (int i = 0; i < sheets; i++) { log.debug("wb = " + i); this.workbook.cloneSheet(1); } PrintSetup printSetting = this.workbook.getSheetAt(1).getPrintSetup(); for (int i = 2; i < this.workbook.getNumberOfSheets(); i++) { this.workbook.getSheetAt(i).getPrintSetup().setLandscape(printSetting.getLandscape()); this.workbook.getSheetAt(i).getPrintSetup().setPaperSize(printSetting.getPaperSize()); } for (int i = 0; i < this.workbook.getNumberOfSheets(); i++) { this.workbook.getSheetAt(i).getFooter().setRight("dataforms.jar " + Page.getDataformsVersion()); } }
/** * 印刷設定の文字列表現を取得する。 * * @param printSetup 印刷設定 * @return 印刷設定の文字列表現 */ public static String getPrintSetupString( PrintSetup printSetup) { StringBuffer sb = new StringBuffer(); if ( printSetup != null) { sb.append( "PaperSize=").append( printSetup.getPaperSize()).append( ","); sb.append( "Scale=").append( printSetup.getScale()).append( ","); sb.append( "PageStart=").append( printSetup.getPageStart()).append( ","); sb.append( "FitWidth=").append( printSetup.getFitWidth()).append( ","); sb.append( "FitHeight=").append( printSetup.getFitHeight()).append( ","); sb.append( "LeftToRight=").append( printSetup.getLeftToRight()).append( ","); sb.append( "Landscape=").append( printSetup.getLandscape()).append( ","); sb.append( "ValidSettings=").append( printSetup.getValidSettings()).append( ","); sb.append( "NoColor=").append( printSetup.getNoColor()).append( ","); sb.append( "Draft=").append( printSetup.getDraft()).append( ","); sb.append( "Notes=").append( printSetup.getNotes()).append( ","); sb.append( "NoOrientation=").append( printSetup.getNoOrientation()).append( ","); sb.append( "UsePage=").append( printSetup.getUsePage()).append( ","); sb.append( "HResolution=").append( printSetup.getHResolution()).append( ","); sb.append( "VResolution=").append( printSetup.getVResolution()).append( ","); sb.append( "HeaderMargin=").append( printSetup.getHeaderMargin()).append( ","); sb.append( "FooterMargin=").append( printSetup.getFooterMargin()).append( ","); sb.append( "Copies=").append( printSetup.getCopies()); } return sb.toString(); }
private void setPaperSize() { String pageFormat = bean.getReportLayout().getPageFormat(); short size = 0; if (ReportLayout.LETTER.equals(pageFormat)) { size = PrintSetup.LETTER_PAPERSIZE; } else if (ReportLayout.A3.equals(pageFormat)) { size = PrintSetup.A3_PAPERSIZE; } else if (ReportLayout.A4.equals(pageFormat)) { size = PrintSetup.A4_PAPERSIZE; } else if (ReportLayout.LEGAL.equals(pageFormat)) { size = PrintSetup.LEGAL_PAPERSIZE; } else if (ReportLayout.LEDGER.equals(pageFormat)) { size = PrintSetup.LEDGER_PAPERSIZE; } else if (ReportLayout.TABLOID.equals(pageFormat)) { size = PrintSetup.TABLOID_PAPERSIZE; } if (size != 0) { xlsSheet.getPrintSetup().setPaperSize(size); } }
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; }
private static CellStyle initializeSheet(Workbook wb, Sheet sheet) { PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); sheet.setFitToPage(true); sheet.setHorizontallyCenter(true); CellStyle styleTitle; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 12); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); titleFont.setFontName("Arial"); styleTitle = wb.createCellStyle(); styleTitle.setFont(titleFont); return styleTitle; }
/** * Initial sheet setup. Override this method to specifically change initial, * sheet-wide, settings. */ protected void initialSheetSetup() { final PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); sheet.setFitToPage(true); sheet.setHorizontallyCenter(true); if ((isHierarchical()) && (displayTotals)) { hierarchicalTotalsSheet = workbook.createSheet("tempHts"); } }
protected Sheet createNewSheet(List<? extends IExportColumn<?>> columnList) { Sheet s = createSheet(); s.getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE); s.getPrintSetup().setLandscape(true); renderHeader(columnList, s); return s; }
protected void initPageSetup(Sheet sheet) { // print and page setup sheet.setPrintGridlines(true); sheet.setDisplayGridlines(true); sheet.setAutobreaks(true); sheet.setHorizontallyCenter(true); // set content size when printing PrintSetup printSetup = sheet.getPrintSetup(); sheet.setFitToPage(true); printSetup.setFitHeight(Short.MAX_VALUE); printSetup.setFitWidth((short) 1); }
/** * fromIdxのシートからtoIdxシートへの印刷設定のコピーを行う * @param workbook fromIdx、toIdxのシートを含むworkbook * @param fromIdx コピー元シートのインデックス * @param sheet コピー先シート */ public static void copyPrintSetup( Workbook workbook, int fromIdx, Sheet toSheet) { Sheet fromSheet = workbook.getSheetAt( fromIdx); // 印刷設定 PrintSetup fromPrintSetup = fromSheet.getPrintSetup(); PrintSetup printSetup = toSheet.getPrintSetup(); printSetup.setCopies( fromPrintSetup.getCopies()); printSetup.setDraft( fromPrintSetup.getDraft()); printSetup.setFitHeight( fromPrintSetup.getFitHeight()); printSetup.setFitWidth( fromPrintSetup.getFitWidth()); printSetup.setFooterMargin( fromPrintSetup.getFooterMargin()); printSetup.setHeaderMargin( fromPrintSetup.getHeaderMargin()); printSetup.setHResolution( fromPrintSetup.getHResolution()); printSetup.setLandscape( fromPrintSetup.getLandscape()); printSetup.setLeftToRight( fromPrintSetup.getLeftToRight()); printSetup.setNoColor( fromPrintSetup.getNoColor()); printSetup.setNoOrientation( fromPrintSetup.getNoOrientation()); printSetup.setPageStart( fromPrintSetup.getPageStart()); printSetup.setPaperSize( fromPrintSetup.getPaperSize()); printSetup.setScale( fromPrintSetup.getScale()); printSetup.setUsePage( fromPrintSetup.getUsePage()); printSetup.setValidSettings( fromPrintSetup.getValidSettings()); printSetup.setVResolution( fromPrintSetup.getVResolution()); // 印刷範囲 String printArea = workbook.getPrintArea( fromIdx); if ( printArea != null) { if ( printArea.contains( "!")) { printArea = printArea.substring( printArea.indexOf( "!") + 1); } int toIdx = workbook.getSheetIndex( toSheet); workbook.setPrintArea( toIdx, printArea); } // タイトル行、タイトル列 toSheet.setRepeatingColumns( fromSheet.getRepeatingColumns()); toSheet.setRepeatingRows( fromSheet.getRepeatingRows()); }
/** * Convert a BIRT paper size string into a POI PrintSetup.*PAPERSIZE constant. * @param name * The paper size as a BIRT string. * @return * A POI PrintSetup.*PAPERSIZE constant. */ public short getPaperSizeFromString( String name ) { if( "a4".equals(name) ) { return PrintSetup.A4_PAPERSIZE; } else if( "a3".equals(name)) { return PrintSetup.A3_PAPERSIZE; } else if( "us-letter".equals(name)) { return PrintSetup.LETTER_PAPERSIZE; } return PrintSetup.A4_PAPERSIZE; }
private void setupPageSize(HandlerState state, IPageContent page) { PrintSetup printSetup = state.currentSheet.getPrintSetup(); printSetup.setPaperSize(state.getSmu().getPaperSizeFromString(page.getPageType())); if( page.getOrientation() != null ) { if( "landscape".equals(page.getOrientation())) { printSetup.setLandscape(true); } } }
protected void configurePrintSetup(Sheet sheet) { PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); sheet.setFitToPage(true); sheet.setHorizontallyCenter(true); }
/** * 复制模板工作表的打印区域到数据工作表中 * * @author ZhengWei(HY) * @createDate 2017-03-17 * @version v1.0 * * @param i_FromSheet 源工作表 * @param i_ToSheet 目标工作表 */ public final static void copyPrintSetup(Sheet i_FromSheet ,Sheet i_ToSheet) { PrintSetup v_FromPrintSetup = i_FromSheet.getPrintSetup(); PrintSetup v_ToPrintSetup = i_ToSheet .getPrintSetup(); v_ToPrintSetup.setCopies( v_FromPrintSetup.getCopies()); v_ToPrintSetup.setDraft( v_FromPrintSetup.getDraft()); // 值为true时,表示用草稿品质打印 v_ToPrintSetup.setFitHeight( v_FromPrintSetup.getFitHeight()); // 设置页高 v_ToPrintSetup.setFitWidth( v_FromPrintSetup.getFitWidth()); // 设置页宽 v_ToPrintSetup.setFooterMargin( v_FromPrintSetup.getFooterMargin()); v_ToPrintSetup.setHeaderMargin( v_FromPrintSetup.getHeaderMargin()); v_ToPrintSetup.setHResolution( v_FromPrintSetup.getHResolution()); v_ToPrintSetup.setLandscape( v_FromPrintSetup.getLandscape()); // true,则表示页面方向为横向;否则为纵向 v_ToPrintSetup.setLeftToRight( v_FromPrintSetup.getLeftToRight()); // true表示“先行后列”;false表示“先列后行” v_ToPrintSetup.setNoColor( v_FromPrintSetup.getNoColor()); // 值为true时,表示单色打印 v_ToPrintSetup.setNoOrientation(v_FromPrintSetup.getNoOrientation()); v_ToPrintSetup.setNotes( v_FromPrintSetup.getNotes()); // 设置打印批注 v_ToPrintSetup.setPageStart( v_FromPrintSetup.getPageStart()); // 设置打印起始页码 v_ToPrintSetup.setPaperSize( v_FromPrintSetup.getPaperSize()); // 纸张类型 A4纸 HSSFPrintSetup.A4_PAPERSIZE v_ToPrintSetup.setScale( v_FromPrintSetup.getScale()); // 缩放比例80%(设置为0-100之间的值) v_ToPrintSetup.setUsePage( v_FromPrintSetup.getUsePage()); // 设置打印起始页码是否使用"自动" v_ToPrintSetup.setValidSettings(v_FromPrintSetup.getValidSettings()); v_ToPrintSetup.setVResolution( v_FromPrintSetup.getVResolution()); // 设置打印参数 if ( i_ToSheet instanceof HSSFSheet ) { ((HSSFPrintSetup)v_ToPrintSetup).setOptions(((HSSFPrintSetup)v_FromPrintSetup).getOptions()); i_ToSheet.setMargin(HSSFSheet.TopMargin ,i_FromSheet.getMargin(HSSFSheet.TopMargin)); // 页边距(上) i_ToSheet.setMargin(HSSFSheet.BottomMargin ,i_FromSheet.getMargin(HSSFSheet.BottomMargin)); // 页边距(下) i_ToSheet.setMargin(HSSFSheet.LeftMargin ,i_FromSheet.getMargin(HSSFSheet.LeftMargin)); // 页边距(左) i_ToSheet.setMargin(HSSFSheet.RightMargin ,i_FromSheet.getMargin(HSSFSheet.RightMargin)); // 页边距(右) i_ToSheet.setMargin(HSSFSheet.HeaderMargin ,i_FromSheet.getMargin(HSSFSheet.HeaderMargin)); // 页眉 i_ToSheet.setMargin(HSSFSheet.FooterMargin ,i_FromSheet.getMargin(HSSFSheet.FooterMargin)); // 页脚 } else if ( i_ToSheet instanceof SXSSFSheet ) { ((XSSFPrintSetup)v_ToPrintSetup).setOrientation(((XSSFPrintSetup)v_FromPrintSetup).getOrientation()); // 设置方向 i_ToSheet.setMargin(SXSSFSheet.TopMargin ,i_FromSheet.getMargin(SXSSFSheet.TopMargin)); // 页边距(上) i_ToSheet.setMargin(SXSSFSheet.BottomMargin ,i_FromSheet.getMargin(SXSSFSheet.BottomMargin)); // 页边距(下) i_ToSheet.setMargin(SXSSFSheet.LeftMargin ,i_FromSheet.getMargin(SXSSFSheet.LeftMargin)); // 页边距(左) i_ToSheet.setMargin(SXSSFSheet.RightMargin ,i_FromSheet.getMargin(SXSSFSheet.RightMargin)); // 页边距(右) i_ToSheet.setMargin(SXSSFSheet.HeaderMargin ,i_FromSheet.getMargin(SXSSFSheet.HeaderMargin)); // 页眉 i_ToSheet.setMargin(SXSSFSheet.FooterMargin ,i_FromSheet.getMargin(SXSSFSheet.FooterMargin)); // 页脚 } else if ( i_ToSheet instanceof XSSFSheet ) { ((XSSFPrintSetup)v_ToPrintSetup).setOrientation(((XSSFPrintSetup)v_FromPrintSetup).getOrientation()); // 设置方向 i_ToSheet.setMargin(XSSFSheet.TopMargin ,i_FromSheet.getMargin(XSSFSheet.TopMargin)); // 页边距(上) i_ToSheet.setMargin(XSSFSheet.BottomMargin ,i_FromSheet.getMargin(XSSFSheet.BottomMargin)); // 页边距(下) i_ToSheet.setMargin(XSSFSheet.LeftMargin ,i_FromSheet.getMargin(XSSFSheet.LeftMargin)); // 页边距(左) i_ToSheet.setMargin(XSSFSheet.RightMargin ,i_FromSheet.getMargin(XSSFSheet.RightMargin)); // 页边距(右) i_ToSheet.setMargin(XSSFSheet.HeaderMargin ,i_FromSheet.getMargin(XSSFSheet.HeaderMargin)); // 页眉 i_ToSheet.setMargin(XSSFSheet.FooterMargin ,i_FromSheet.getMargin(XSSFSheet.FooterMargin)); // 页脚 } copyHeaderFooter(i_FromSheet.getHeader() ,i_ToSheet.getHeader()); copyHeaderFooter(i_FromSheet.getFooter() ,i_ToSheet.getFooter()); }
public PrintSetup getPrintSetup() { return sheet.getPrintSetup(); }
/** * Not supported */ @Override public PrintSetup getPrintSetup() { throw new UnsupportedOperationException(); }