org.apache.poi.xssf.usermodel.XSSFPrintSetup Java Examples

The following examples show how to use org.apache.poi.xssf.usermodel.XSSFPrintSetup. 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 Project: ureport   Author: youseries   File: ExcelBuilder.java    License: Apache License 2.0 6 votes vote down vote up
protected Sheet createSheet(SXSSFWorkbook wb,Paper paper,String name){
	Sheet sheet = null;
	if(name==null){
		sheet=wb.createSheet();
	}else{			
		sheet=wb.createSheet(name);
	}
	PaperType paperType=paper.getPaperType();
	XSSFPrintSetup printSetup=(XSSFPrintSetup)sheet.getPrintSetup();
	Orientation orientation=paper.getOrientation();
	if(orientation.equals(Orientation.landscape)){
		printSetup.setOrientation(PrintOrientation.LANDSCAPE);			
	}
	setupPaper(paperType, printSetup);
	int leftMargin=paper.getLeftMargin();
	int rightMargin=paper.getRightMargin();
	int topMargin=paper.getTopMargin();
	int bottomMargin=paper.getBottomMargin();
	sheet.setMargin(Sheet.LeftMargin, UnitUtils.pointToInche(leftMargin));
	sheet.setMargin(Sheet.RightMargin, UnitUtils.pointToInche(rightMargin));
	sheet.setMargin(Sheet.TopMargin, UnitUtils.pointToInche(topMargin));
	sheet.setMargin(Sheet.BottomMargin, UnitUtils.pointToInche(bottomMargin));
	return sheet;
}
 
Example #2
Source Project: birt   Author: eclipse   File: PageLayoutTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testRunReportXlsx() throws BirtException, IOException {

	InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xlsx");
	assertNotNull(inputStream);
	try {
		
		XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
		assertNotNull(workbook);
		
		assertEquals( 1, workbook.getNumberOfSheets() );
		assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
		
		XSSFSheet sheet0 = workbook.getSheetAt(0);
		XSSFPrintSetup printSetup = sheet0.getPrintSetup();
		assertEquals( PaperSize.A4_PAPER,  printSetup.getPaperSizeEnum() );
		assertEquals( PrintOrientation.LANDSCAPE, printSetup.getOrientation() );
		assertEquals( 1.0 / 2.54, printSetup.getHeaderMargin(), 0.01 );
		assertEquals( 1.0 / 2.54, printSetup.getFooterMargin(), 0.01 );
		assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
		assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
		assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
		assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
		
	} finally {
		inputStream.close();
	}
}
 
Example #3
Source Project: birt   Author: eclipse   File: PageLayoutTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testRunReportPixelsXlsx() throws BirtException, IOException {

	InputStream inputStream = runAndRenderReport("PageLayoutPixels.rptdesign", "xlsx");
	assertNotNull(inputStream);
	try {
		
		XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
		assertNotNull(workbook);
		
		assertEquals( 1, workbook.getNumberOfSheets() );
		assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());
		
		XSSFSheet sheet0 = workbook.getSheetAt(0);
		XSSFPrintSetup printSetup = sheet0.getPrintSetup();
		assertEquals( PaperSize.A4_PAPER,  printSetup.getPaperSizeEnum() );
		assertEquals( PrintOrientation.LANDSCAPE, printSetup.getOrientation() );
		assertEquals( 0.3, printSetup.getHeaderMargin(), 0.01 );
		assertEquals( 0.3, printSetup.getFooterMargin(), 0.01 );
		assertEquals( 0.7, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
		assertEquals( 0.7, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
		assertEquals( 0.75, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
		assertEquals( 0.75, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );
		
	} finally {
		inputStream.close();
	}
}
 
Example #4
Source Project: ureport   Author: youseries   File: ExcelBuilder.java    License: Apache License 2.0 4 votes vote down vote up
protected boolean setupPaper(PaperType paperType, XSSFPrintSetup printSetup) {
	boolean setup=false;
	switch(paperType){
		case A0:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case A1:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case A2:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case A3:				
			printSetup.setPaperSize(PaperSize.A3_PAPER);
			setup=true;
			break;
		case A4:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			setup=true;
			break;
		case A5:
			printSetup.setPaperSize(PaperSize.A5_PAPER);
			setup=true;
			break;
		case A6:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case A7:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case A8:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case A9:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case A10:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case B0:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case B1:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case B2:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case B3:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case B4:
			printSetup.setPaperSize(PaperSize.B4_PAPER);
			setup=true;
			break;
		case B5:
			printSetup.setPaperSize(PaperSize.B4_PAPER);
			setup=true;
			break;
		case B6:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case B7:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case B8:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case B9:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case B10:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
		case CUSTOM:
			printSetup.setPaperSize(PaperSize.A4_PAPER);
			break;
	}
	return setup;
}
 
Example #5
Source Project: hy.common.report   Author: HY-Org   File: ExcelHelp.java    License: 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());
}