org.apache.poi.ss.usermodel.PrintSetup Java Examples

The following examples show how to use org.apache.poi.ss.usermodel.PrintSetup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExportTimetableXLS.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected Sheet createSheet(String name) {
	Sheet sheet = null;
	try {
		sheet = (name == null ? iWorkbook.createSheet() : iWorkbook.createSheet(name.replace('/', '-').replace('\\','-').replace('?', ' ').replace('*', ' ').replace(':', '-').replace('[', '(').replace(']', ')')));
	} catch (IllegalArgumentException e) {
		sheet = iWorkbook.createSheet();
	}
	sheet.setDisplayGridlines(false);
	sheet.setPrintGridlines(false);
	sheet.setFitToPage(true);
	sheet.setHorizontallyCenter(true);
       PrintSetup printSetup = sheet.getPrintSetup();
       printSetup.setLandscape(true);
       sheet.setAutobreaks(true);
       printSetup.setFitHeight((short)1);
       printSetup.setFitWidth((short)1);
       return sheet;
}
 
Example #2
Source File: ExcelPrintSetupFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Performs the page setup and searches a matching page format for the report.
 *
 * @param printSetup
 *          the print setup object of the current sheet.
 * @param pageformat
 *          the pageformat defined for the report.
 * @param paperdef
 *          the excel paper size property (may be null).
 * @param paperOrientation
 *          the paper orientation, either "Landscape" or "Portrait"
 */
public static void performPageSetup( final PrintSetup printSetup, final PhysicalPageBox pageformat,
    final String paperdef, final String paperOrientation ) {
  short pageCode = ExcelPrintSetupFactory.parsePaperSizeProperty( paperdef );
  if ( pageCode == -1 ) {
    pageCode = ExcelPrintSetupFactory.computePaperSize( pageformat );
  }
  if ( pageCode != -1 ) {
    printSetup.setPaperSize( pageCode );
  }
  if ( paperOrientation != null && paperOrientation.equals( "auto" ) == false ) {
    printSetup.setLandscape( "Landscape".equalsIgnoreCase( paperOrientation ) );
  } else {
    final boolean landscape = pageformat.getWidth() > pageformat.getHeight();
    printSetup.setLandscape( landscape );
  }
}
 
Example #3
Source File: ExportEventsImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: ExcelHandler.java    From development with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: StyleManagerUtils.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: PageHandler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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);
		}
	}
}
 
Example #7
Source File: Util.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
private static void copySheetSettings(Sheet newSheet, Sheet sheetToCopy) {

		newSheet.setAutobreaks(sheetToCopy.getAutobreaks());
		newSheet.setDefaultColumnWidth(sheetToCopy.getDefaultColumnWidth());
		newSheet.setDefaultRowHeight(sheetToCopy.getDefaultRowHeight());
		newSheet.setDefaultRowHeightInPoints(sheetToCopy.getDefaultRowHeightInPoints());
		newSheet.setDisplayGuts(sheetToCopy.getDisplayGuts());
		newSheet.setFitToPage(sheetToCopy.getFitToPage());

		newSheet.setForceFormulaRecalculation(sheetToCopy.getForceFormulaRecalculation());

		PrintSetup sheetToCopyPrintSetup = sheetToCopy.getPrintSetup();
		PrintSetup newSheetPrintSetup = newSheet.getPrintSetup();

		newSheetPrintSetup.setPaperSize(sheetToCopyPrintSetup.getPaperSize());
		newSheetPrintSetup.setScale(sheetToCopyPrintSetup.getScale());
		newSheetPrintSetup.setPageStart(sheetToCopyPrintSetup.getPageStart());
		newSheetPrintSetup.setFitWidth(sheetToCopyPrintSetup.getFitWidth());
		newSheetPrintSetup.setFitHeight(sheetToCopyPrintSetup.getFitHeight());
		newSheetPrintSetup.setLeftToRight(sheetToCopyPrintSetup.getLeftToRight());
		newSheetPrintSetup.setLandscape(sheetToCopyPrintSetup.getLandscape());
		newSheetPrintSetup.setValidSettings(sheetToCopyPrintSetup.getValidSettings());
		newSheetPrintSetup.setNoColor(sheetToCopyPrintSetup.getNoColor());
		newSheetPrintSetup.setDraft(sheetToCopyPrintSetup.getDraft());
		newSheetPrintSetup.setNotes(sheetToCopyPrintSetup.getNotes());
		newSheetPrintSetup.setNoOrientation(sheetToCopyPrintSetup.getNoOrientation());
		newSheetPrintSetup.setUsePage(sheetToCopyPrintSetup.getUsePage());
		newSheetPrintSetup.setHResolution(sheetToCopyPrintSetup.getHResolution());
		newSheetPrintSetup.setVResolution(sheetToCopyPrintSetup.getVResolution());
		newSheetPrintSetup.setHeaderMargin(sheetToCopyPrintSetup.getHeaderMargin());
		newSheetPrintSetup.setFooterMargin(sheetToCopyPrintSetup.getFooterMargin());
		newSheetPrintSetup.setCopies(sheetToCopyPrintSetup.getCopies());

		Header sheetToCopyHeader = sheetToCopy.getHeader();
		Header newSheetHeader = newSheet.getHeader();
		newSheetHeader.setCenter(sheetToCopyHeader.getCenter());
		newSheetHeader.setLeft(sheetToCopyHeader.getLeft());
		newSheetHeader.setRight(sheetToCopyHeader.getRight());

		Footer sheetToCopyFooter = sheetToCopy.getFooter();
		Footer newSheetFooter = newSheet.getFooter();
		newSheetFooter.setCenter(sheetToCopyFooter.getCenter());
		newSheetFooter.setLeft(sheetToCopyFooter.getLeft());
		newSheetFooter.setRight(sheetToCopyFooter.getRight());

		newSheet.setHorizontallyCenter(sheetToCopy.getHorizontallyCenter());
		newSheet.setMargin(Sheet.LeftMargin, sheetToCopy.getMargin(Sheet.LeftMargin));
		newSheet.setMargin(Sheet.RightMargin, sheetToCopy.getMargin(Sheet.RightMargin));
		newSheet.setMargin(Sheet.TopMargin, sheetToCopy.getMargin(Sheet.TopMargin));
		newSheet.setMargin(Sheet.BottomMargin, sheetToCopy.getMargin(Sheet.BottomMargin));

		newSheet.setPrintGridlines(sheetToCopy.isPrintGridlines());
		newSheet.setRowSumsBelow(sheetToCopy.getRowSumsBelow());
		newSheet.setRowSumsRight(sheetToCopy.getRowSumsRight());
		newSheet.setVerticallyCenter(sheetToCopy.getVerticallyCenter());
		newSheet.setDisplayFormulas(sheetToCopy.isDisplayFormulas());
		newSheet.setDisplayGridlines(sheetToCopy.isDisplayGridlines());
		newSheet.setDisplayRowColHeadings(sheetToCopy.isDisplayRowColHeadings());
		newSheet.setDisplayZeros(sheetToCopy.isDisplayZeros());
		newSheet.setPrintGridlines(sheetToCopy.isPrintGridlines());
		newSheet.setRightToLeft(sheetToCopy.isRightToLeft());
		newSheet.setZoom(1, 1);
		copyPrintTitle(newSheet, sheetToCopy);
	}
 
Example #8
Source File: ExcelHelp.java    From hy.common.report with Apache License 2.0 4 votes vote down vote up
/**
 * 复制模板工作表的打印区域到数据工作表中
 * 
 * @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));  // 页脚
    }
    
    i_ToSheet.setHorizontallyCenter(i_FromSheet.getHorizontallyCenter());  // 设置打印页面为水平居中
    i_ToSheet.setVerticallyCenter(  i_FromSheet.getVerticallyCenter());    // 设置打印页面为垂直居中
    
    copyHeaderFooter(i_FromSheet.getHeader() ,i_ToSheet.getHeader());
    copyHeaderFooter(i_FromSheet.getFooter() ,i_ToSheet.getFooter());
}
 
Example #9
Source File: XLSPrinter.java    From unitime with Apache License 2.0 4 votes vote down vote up
public XLSPrinter(OutputStream output, boolean checkLast) {
	iOutput = output;
	iCheckLast = checkLast;
	iWorkbook = new HSSFWorkbook();
	iSheet = iWorkbook.createSheet();
	iSheet.setDisplayGridlines(false);
	iSheet.setPrintGridlines(false);
	iSheet.setFitToPage(true);
	iSheet.setHorizontallyCenter(true);
       PrintSetup printSetup = iSheet.getPrintSetup();
       printSetup.setLandscape(true);
       iSheet.setAutobreaks(true);
       printSetup.setFitHeight((short)1);
       printSetup.setFitWidth((short)1);
       iStyles = new HashMap<String, CellStyle>();
       
       CellStyle style;
       
       style = iWorkbook.createCellStyle();
       style.setBorderBottom(BorderStyle.THIN);
       style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
       style.setAlignment(HorizontalAlignment.LEFT);
       style.setVerticalAlignment(VerticalAlignment.TOP);
       style.setFont(getFont(true, false, false, Color.BLACK));
       style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
       style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
       style.setWrapText(true);
       iStyles.put("header", style);
       
       style = iWorkbook.createCellStyle();
       style.setAlignment(HorizontalAlignment.LEFT);
       style.setVerticalAlignment(VerticalAlignment.TOP);
       style.setFont(getFont(false, false, false, Color.BLACK));
       style.setWrapText(true);
       iStyles.put("plain", style);
       
       style = iWorkbook.createCellStyle();
       style.setAlignment(HorizontalAlignment.RIGHT);
       style.setVerticalAlignment(VerticalAlignment.TOP);
       style.setFont(getFont(false, false, false, Color.BLACK));
       iStyles.put("number", style);
}
 
Example #10
Source File: StreamingSheet.java    From data-prep with Apache License 2.0 4 votes vote down vote up
/**
 * Not supported
 */
@Override
public PrintSetup getPrintSetup() {
    throw new UnsupportedOperationException();
}
 
Example #11
Source File: FilteredSheet.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public PrintSetup getPrintSetup() {
	return sheet.getPrintSetup();
}
 
Example #12
Source File: StreamingSheet.java    From excel-streaming-reader with Apache License 2.0 4 votes vote down vote up
/**
 * Not supported
 */
@Override
public PrintSetup getPrintSetup() {
  throw new UnsupportedOperationException();
}
 
Example #13
Source File: ExcelPrinterBase.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureSheetPaperSize( final Sheet sheet, final PhysicalPageBox page ) {
  Configuration config = getConfig();
  final String paper =
      config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.Paper" );
  final String orientation =
      config
          .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.PaperOrientation" );
  final short scale =
      (short) ParserUtil
          .parseInt(
              config
                  .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.PrintScaleFactor" ),
              100 );
  final short hres =
      (short) ParserUtil
          .parseInt(
              config
                  .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.PrintHorizontalResolution" ),
              -1 );
  final short vres =
      (short) ParserUtil
          .parseInt(
              config
                  .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.PrintVerticalResolution" ),
              -1 );
  final boolean noColors =
      "true".equals( config
          .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.PrintNoColors" ) );
  final boolean notes =
      "true".equals( config
          .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.PrintNotes" ) );
  final boolean usePage =
      "true".equals( config
          .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.PrintUsePage" ) );
  final boolean draft =
      "true".equals( config
          .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.PrintDraft" ) );

  final PrintSetup printSetup = sheet.getPrintSetup();
  ExcelPrintSetupFactory.performPageSetup( printSetup, page, paper, orientation );
  printSetup.setScale( scale );
  printSetup.setNoColor( noColors );
  printSetup.setNotes( notes );
  printSetup.setUsePage( usePage );
  if ( hres > 0 ) {
    printSetup.setHResolution( hres );
  }
  if ( vres > 0 ) {
    printSetup.setVResolution( vres );
  }
  printSetup.setDraft( draft );

  final boolean displayGridLines =
      "true"
          .equals( config
              .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.GridLinesDisplayed" ) );
  final boolean printGridLines =
      "true"
          .equals( config
              .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.xls.GridLinesPrinted" ) );
  sheet.setDisplayGridlines( displayGridLines );
  sheet.setPrintGridlines( printGridLines );
}