Java Code Examples for org.apache.poi.ss.usermodel.Sheet#setMargin()
The following examples show how to use
org.apache.poi.ss.usermodel.Sheet#setMargin() .
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: Excel97Producer.java From ureport with Apache License 2.0 | 6 votes |
private Sheet createSheet(HSSFWorkbook wb,Paper paper,String name){ Sheet sheet = null; if(name==null){ sheet=wb.createSheet(); }else{ sheet=wb.createSheet(name); } PaperType paperType=paper.getPaperType(); HSSFPrintSetup printSetup=(HSSFPrintSetup)sheet.getPrintSetup(); Orientation orientation=paper.getOrientation(); if(orientation.equals(Orientation.landscape)){ printSetup.setLandscape(true); } 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 File: ExcelBuilder.java From ureport with Apache License 2.0 | 6 votes |
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 3
Source File: StyleManagerXUtils.java From birt with Eclipse Public License 1.0 | 6 votes |
@Override public void prepareMarginDimensions(Sheet sheet, IPageContent page) { double headerHeight = 0.5; double footerHeight = 0.5; if( ( page.getHeaderHeight() != null ) && isAbsolute( page.getHeaderHeight() ) ) { headerHeight = page.getHeaderHeight().convertTo(DimensionType.UNITS_IN); sheet.setMargin(Sheet.HeaderMargin, headerHeight); } if( ( page.getFooterHeight() != null ) && isAbsolute( page.getFooterHeight() ) ) { footerHeight = page.getFooterHeight().convertTo(DimensionType.UNITS_IN); sheet.setMargin(Sheet.FooterMargin, footerHeight); } if( ( page.getMarginBottom() != null ) && isAbsolute( page.getMarginBottom() ) ) { sheet.setMargin(Sheet.BottomMargin, footerHeight + page.getMarginBottom().convertTo(DimensionType.UNITS_IN)); } if( ( page.getMarginLeft() != null ) && isAbsolute( page.getMarginLeft() ) ) { sheet.setMargin(Sheet.LeftMargin, page.getMarginLeft().convertTo(DimensionType.UNITS_IN)); } if( ( page.getMarginRight() != null ) && isAbsolute( page.getMarginRight() ) ) { sheet.setMargin(Sheet.RightMargin, page.getMarginRight().convertTo(DimensionType.UNITS_IN)); } if( ( page.getMarginTop() != null ) && isAbsolute( page.getMarginTop() ) ) { sheet.setMargin(Sheet.TopMargin, headerHeight + page.getMarginTop().convertTo(DimensionType.UNITS_IN)); } }
Example 4
Source File: StyleManagerHUtils.java From birt with Eclipse Public License 1.0 | 6 votes |
@Override public void prepareMarginDimensions(Sheet sheet, IPageContent page) { double headerHeight = 0.5; double footerHeight = 0.5; if( ( page.getHeaderHeight() != null ) && isAbsolute( page.getHeaderHeight() ) ) { headerHeight = page.getHeaderHeight().convertTo(DimensionType.UNITS_IN); sheet.getPrintSetup().setHeaderMargin(headerHeight); } if( ( page.getFooterHeight() != null ) && isAbsolute( page.getFooterHeight() ) ) { footerHeight = page.getFooterHeight().convertTo(DimensionType.UNITS_IN); sheet.getPrintSetup().setFooterMargin(footerHeight); } if( ( page.getMarginBottom() != null ) && isAbsolute( page.getMarginBottom() ) ) { sheet.setMargin(Sheet.BottomMargin, footerHeight + page.getMarginBottom().convertTo(DimensionType.UNITS_IN)); } if( ( page.getMarginLeft() != null ) && isAbsolute( page.getMarginLeft() ) ) { sheet.setMargin(Sheet.LeftMargin, page.getMarginLeft().convertTo(DimensionType.UNITS_IN)); } if( ( page.getMarginRight() != null ) && isAbsolute( page.getMarginRight() ) ) { sheet.setMargin(Sheet.RightMargin, page.getMarginRight().convertTo(DimensionType.UNITS_IN)); } if( ( page.getMarginTop() != null ) && isAbsolute( page.getMarginTop() ) ) { sheet.setMargin(Sheet.TopMargin, headerHeight + page.getMarginTop().convertTo(DimensionType.UNITS_IN)); } }
Example 5
Source File: Util.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
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 6
Source File: ExcelHelp.java From hy.common.report with Apache License 2.0 | 4 votes |
/** * 复制模板工作表的打印区域到数据工作表中 * * @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()); }