From f3d9f2bdd9469742f8a90eb55dece945830af0bd Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 27 Feb 2012 15:22:22 +0000 Subject: [PATCH] Bugzilla 52574 - support setting header / footer page margins in HSSF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1294181 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 2 ++ .../apache/poi/hssf/usermodel/HSSFSheet.java | 20 +++++++++++++++++-- .../apache/poi/xssf/usermodel/XSSFSheet.java | 2 +- .../poi/ss/usermodel/BaseTestSheet.java | 5 +++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index cbd39ea9de..7bb0f71feb 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,8 @@ + 52574 - support setting header / footer page margins in HSSF + 52583 - fixed WorkbookUtil#createSafeSheetName to escape colon 51710 - fixed reading shared formulas in XSSF 52708 - misc improvements in CellFormat 52690 - added a getter for length of encrypted data in Ecma and Agile decryptors diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index a1bc0f36b7..48e87b85a8 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -1062,7 +1062,14 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { * @return the size of the margin */ public double getMargin(short margin) { - return _sheet.getPageSettings().getMargin(margin); + switch (margin){ + case FooterMargin: + return _sheet.getPageSettings().getPrintSetup().getFooterMargin(); + case HeaderMargin: + return _sheet.getPageSettings().getPrintSetup().getHeaderMargin(); + default: + return _sheet.getPageSettings().getMargin(margin); + } } /** @@ -1071,7 +1078,16 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { * @param size the size of the margin */ public void setMargin(short margin, double size) { - _sheet.getPageSettings().setMargin(margin, size); + switch (margin){ + case FooterMargin: + _sheet.getPageSettings().getPrintSetup().setFooterMargin(size); + break; + case HeaderMargin: + _sheet.getPageSettings().getPrintSetup().setHeaderMargin(size); + break; + default: + _sheet.getPageSettings().setMargin(margin, size); + } } private WorksheetProtectionBlock getProtectionBlock() { diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 2d0566a3d3..0235e4150f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -2673,7 +2673,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { CTCellFormula sf = (CTCellFormula)f.copy(); CellRangeAddress sfRef = CellRangeAddress.valueOf(sf.getRef()); CellReference cellRef = new CellReference(cell); - // If the shared formula range preceeds the master cell then the preseeing part is discarded, e.g. + // If the shared formula range preceeds the master cell then the preceding part is discarded, e.g. // if the cell is E60 and the shared formula range is C60:M85 then the effective range is E60:M85 // see more details in https://issues.apache.org/bugzilla/show_bug.cgi?id=51710 if(cellRef.getCol() > sfRef.getFirstColumn() || cellRef.getRow() > sfRef.getFirstRow()){ diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java index bd2b8f3771..7a3c213bab 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java @@ -557,6 +557,11 @@ public abstract class BaseTestSheet extends TestCase { sheet.setMargin(Sheet.BottomMargin, 13.0); assertEquals(13.0, sheet.getMargin(Sheet.BottomMargin), 0.0); + sheet.setMargin(Sheet.FooterMargin, 5.6); + assertEquals(5.6, sheet.getMargin(Sheet.FooterMargin), 0.0); + sheet.setMargin(Sheet.HeaderMargin, 11.5); + assertEquals(11.5, sheet.getMargin(Sheet.HeaderMargin), 0.0); + // incorrect margin constant try { sheet.setMargin((short) 65, 15); -- 2.39.5