org.apache.poi.hssf.usermodel.HSSFPrintSetup Java Examples
The following examples show how to use
org.apache.poi.hssf.usermodel.HSSFPrintSetup.
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: JRXlsMetadataExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
private void updateHeaderFooterMargin(Integer marginValue, boolean isHeaderMargin) { if(marginValue != null) { HSSFPrintSetup printSetup = sheet.getPrintSetup(); double margin = LengthUtil.inch(marginValue); if(isHeaderMargin) { if(margin > printSetup.getHeaderMargin()) { printSetup.setHeaderMargin(margin); } } else { if(margin > printSetup.getFooterMargin()) { printSetup.setFooterMargin(margin); } } } }
Example #3
Source File: ExportEventsImpl.java From neoscada with Eclipse Public License 1.0 | 5 votes |
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: JRXlsExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void closeSheet() { if (sheet == null) { return; } HSSFPrintSetup printSetup = sheet.getPrintSetup(); if (isValidScale(sheetInfo.sheetPageScale)) { printSetup.setScale((short)sheetInfo.sheetPageScale.intValue()); } else { XlsReportConfiguration configuration = getCurrentItemConfiguration(); Integer fitWidth = configuration.getFitWidth(); if (fitWidth != null) { printSetup.setFitWidth(fitWidth.shortValue()); sheet.setAutobreaks(true); } Integer fitHeight = configuration.getFitHeight(); fitHeight = fitHeight == null ? (Boolean.TRUE == configuration.isAutoFitPageHeight() ? (pageIndex - sheetInfo.sheetFirstPageIndex) : null) : fitHeight; if (fitHeight != null) { printSetup.setFitHeight(fitHeight.shortValue()); sheet.setAutobreaks(true); } } }
Example #5
Source File: JRXlsMetadataExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void closeSheet() { if (sheet == null) { return; } HSSFPrintSetup printSetup = sheet.getPrintSetup(); if (isValidScale(sheetInfo.sheetPageScale)) { printSetup.setScale((short)sheetInfo.sheetPageScale.intValue()); } else { XlsReportConfiguration configuration = getCurrentItemConfiguration(); Integer fitWidth = configuration.getFitWidth(); if (fitWidth != null) { printSetup.setFitWidth(fitWidth.shortValue()); sheet.setAutobreaks(true); } Integer fitHeight = configuration.getFitHeight(); fitHeight = fitHeight == null ? (Boolean.TRUE == configuration.isAutoFitPageHeight() ? (pageIndex - sheetInfo.sheetFirstPageIndex) : null) : fitHeight; if (fitHeight != null) { printSetup.setFitHeight(fitHeight.shortValue()); sheet.setAutobreaks(true); } } }
Example #6
Source File: PageLayoutTest.java From birt with Eclipse Public License 1.0 | 5 votes |
@Test public void testRunReportXls() throws BirtException, IOException { InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xls"); assertNotNull(inputStream); try { HSSFWorkbook workbook = new HSSFWorkbook(inputStream); assertNotNull(workbook); assertEquals( 1, workbook.getNumberOfSheets() ); assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName()); HSSFSheet sheet0 = workbook.getSheetAt(0); HSSFPrintSetup printSetup = sheet0.getPrintSetup(); assertEquals( HSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() ); assertEquals( true, printSetup.getLandscape() ); 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 #7
Source File: PageLayoutTest.java From birt with Eclipse Public License 1.0 | 5 votes |
@Test public void testRunReportPixelsXls() throws BirtException, IOException { InputStream inputStream = runAndRenderReport("PageLayoutPixels.rptdesign", "xls"); assertNotNull(inputStream); try { HSSFWorkbook workbook = new HSSFWorkbook(inputStream); assertNotNull(workbook); assertEquals( 1, workbook.getNumberOfSheets() ); assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName()); HSSFSheet sheet0 = workbook.getSheetAt(0); HSSFPrintSetup printSetup = sheet0.getPrintSetup(); assertEquals( HSSFPrintSetup.A4_PAPERSIZE, printSetup.getPaperSize() ); assertEquals( true, printSetup.getLandscape() ); assertEquals( 0.5, printSetup.getHeaderMargin(), 0.01 ); assertEquals( 0.5, printSetup.getFooterMargin(), 0.01 ); assertEquals( 0.75, sheet0.getMargin( Sheet.LeftMargin ), 0.01 ); assertEquals( 0.75, sheet0.getMargin( Sheet.RightMargin ), 0.01 ); assertEquals( 1.0, sheet0.getMargin( Sheet.TopMargin ), 0.01 ); assertEquals( 1.0, sheet0.getMargin( Sheet.BottomMargin ), 0.01 ); } finally { inputStream.close(); } }
Example #8
Source File: Excel97Producer.java From ureport with Apache License 2.0 | 4 votes |
private boolean setupPaper(PaperType paperType, HSSFPrintSetup printSetup) { boolean setup=false; switch(paperType){ case A0: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case A1: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case A2: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case A3: printSetup.setPaperSize(HSSFPrintSetup.A3_PAPERSIZE); setup=true; break; case A4: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); setup=true; break; case A5: printSetup.setPaperSize(HSSFPrintSetup.A5_PAPERSIZE); setup=true; break; case A6: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case A7: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case A8: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case A9: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case A10: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case B0: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case B1: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case B2: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case B3: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case B4: printSetup.setPaperSize(HSSFPrintSetup.B4_PAPERSIZE); setup=true; break; case B5: printSetup.setPaperSize(HSSFPrintSetup.B5_PAPERSIZE); setup=true; break; case B6: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case B7: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case B8: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case B9: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case B10: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; case CUSTOM: printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE); break; } return setup; }
Example #9
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()); }
Example #10
Source File: JRXlsExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
private final short getSuitablePaperSize(SheetPrintSettings printSettings) { if (printSettings == null) { return -1; } long width = 0; long height = 0; short ps = -1; if ((printSettings.getPageWidth() != 0) && (printSettings.getPageHeight() != 0)) { double dWidth = (printSettings.getPageWidth() / 72.0); double dHeight = (printSettings.getPageHeight() / 72.0); height = Math.round(dHeight * 25.4); width = Math.round(dWidth * 25.4); // Compare to ISO 216 A-Series (A3-A5). All other ISO 216 formats // not supported by POI Api yet. for (int i = 2; i < 6; i++) { int w = calculateWidthForDinAN(i); int h = calculateHeightForDinAN(i); if (((w == width) && (h == height)) || ((h == width) && (w == height))) { if (i == 2) { // local A2_PAPERSIZE constant ps = A2_PAPERSIZE; } if (i == 3) { ps = HSSFPrintSetup.A3_PAPERSIZE; } else if (i == 4) { ps = HSSFPrintSetup.A4_PAPERSIZE; } else if (i == 5) { ps = HSSFPrintSetup.A5_PAPERSIZE; } break; } } //envelope sizes if (ps == -1) { // ISO 269 sizes - "Envelope DL" (110 x 220 mm) if (((width == 110) && (height == 220)) || ((width == 220) && (height == 110))) { ps = HSSFPrintSetup.ENVELOPE_DL_PAPERSIZE; } } // Compare to common North American Paper Sizes (ANSI X3.151-1987). if (ps == -1) { // ANSI X3.151-1987 - "Letter" (216 x 279 mm) if (((width == 216) && (height == 279)) || ((width == 279) && (height == 216))) { ps = HSSFPrintSetup.LETTER_PAPERSIZE; } // ANSI X3.151-1987 - "Legal" (216 x 356 mm) if (((width == 216) && (height == 356)) || ((width == 356) && (height == 216))) { ps = HSSFPrintSetup.LEGAL_PAPERSIZE; } // ANSI X3.151-1987 - "Executive" (190 x 254 mm) else if (((width == 190) && (height == 254)) || ((width == 254) && (height == 190))) { ps = HSSFPrintSetup.EXECUTIVE_PAPERSIZE; } // ANSI X3.151-1987 - "Ledger/Tabloid" (279 x 432 mm) // Not supported by POI Api yet. } } return ps; }
Example #11
Source File: JRXlsMetadataExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
private final short getSuitablePaperSize() { if (pageFormat == null) { return -1; } long width = 0; long height = 0; short ps = -1; if ((pageFormat.getPageWidth() != 0) && (pageFormat.getPageHeight() != 0)) { double dWidth = (pageFormat.getPageWidth() / 72.0); double dHeight = (pageFormat.getPageHeight() / 72.0); height = Math.round(dHeight * 25.4); width = Math.round(dWidth * 25.4); // Compare to ISO 216 A-Series (A3-A5). All other ISO 216 formats // not supported by POI Api yet. // A3 papersize also not supported by POI Api yet. for (int i = 4; i < 6; i++) { int w = calculateWidthForDinAN(i); int h = calculateHeightForDinAN(i); if (((w == width) && (h == height)) || ((h == width) && (w == height))) { if (i == 4) { ps = HSSFPrintSetup.A4_PAPERSIZE; } else if (i == 5) { ps = HSSFPrintSetup.A5_PAPERSIZE; } break; } } //envelope sizes if (ps == -1) { // ISO 269 sizes - "Envelope DL" (110 x 220 mm) if (((width == 110) && (height == 220)) || ((width == 220) && (height == 110))) { ps = HSSFPrintSetup.ENVELOPE_DL_PAPERSIZE; } } // Compare to common North American Paper Sizes (ANSI X3.151-1987). if (ps == -1) { // ANSI X3.151-1987 - "Letter" (216 x 279 mm) if (((width == 216) && (height == 279)) || ((width == 279) && (height == 216))) { ps = HSSFPrintSetup.LETTER_PAPERSIZE; } // ANSI X3.151-1987 - "Legal" (216 x 356 mm) if (((width == 216) && (height == 356)) || ((width == 356) && (height == 216))) { ps = HSSFPrintSetup.LEGAL_PAPERSIZE; } // ANSI X3.151-1987 - "Executive" (190 x 254 mm) else if (((width == 190) && (height == 254)) || ((width == 254) && (height == 190))) { ps = HSSFPrintSetup.EXECUTIVE_PAPERSIZE; } // ANSI X3.151-1987 - "Ledger/Tabloid" (279 x 432 mm) // Not supported by POI Api yet. } } return ps; }