aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-07-20 19:32:28 +0000
committerPJ Fanning <fanningpj@apache.org>2022-07-20 19:32:28 +0000
commitfa045845f556538ccc824d1707dd9f23dbb5f25d (patch)
treecb2f3f25ae2e174a316c0a614b86620c34a69fb0
parent53557251978ddb905e81063a79ea8f49d944a026 (diff)
downloadpoi-fa045845f556538ccc824d1707dd9f23dbb5f25d.tar.gz
poi-fa045845f556538ccc824d1707dd9f23dbb5f25d.zip
[bug-55330] add setMargin(PageMargin, double)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902890 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java25
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java29
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java31
-rw-r--r--poi/src/main/java/org/apache/poi/ss/usermodel/Sheet.java14
4 files changed, 84 insertions, 15 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
index b57759f447..b5ad3dfb66 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
@@ -799,12 +799,33 @@ public class SXSSFSheet implements Sheet, OoxmlSheetExtensions {
/**
* Sets the size of the margin in inches.
*
- * @param margin which margin to get
+ * @param margin which margin to set
* @param size the size of the margin
+ * @see Sheet#LeftMargin
+ * @see Sheet#RightMargin
+ * @see Sheet#TopMargin
+ * @see Sheet#BottomMargin
+ * @see Sheet#HeaderMargin
+ * @see Sheet#FooterMargin
+ * @deprecated use {@link #setMargin(PageMargin, double)} instead
*/
@Override
+ @Deprecated
+ @Removal(version = "7.0.0")
public void setMargin(short margin, double size) {
- _sh.setMargin(margin,size);
+ _sh.setMargin(margin, size);
+ }
+
+ /**
+ * Sets the size of the margin in inches.
+ *
+ * @param margin which margin to set
+ * @param size the size of the margin
+ * @since POI 5.2.3
+ */
+ @Override
+ public void setMargin(PageMargin margin, double size) {
+ _sh.setMargin(margin, size);
}
/**
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index 03c395c301..1ce3b03d53 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -1264,7 +1264,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx
/**
* Sets the size of the margin in inches.
*
- * @param margin which margin to get
+ * @param margin which margin to set
* @param size the size of the margin
* @see Sheet#LeftMargin
* @see Sheet#RightMargin
@@ -1272,28 +1272,43 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx
* @see Sheet#BottomMargin
* @see Sheet#HeaderMargin
* @see Sheet#FooterMargin
+ * @deprecated use {@link #setMargin(PageMargin, double)} instead
*/
@Override
+ @Deprecated
+ @Removal(version = "7.0.0")
public void setMargin(short margin, double size) {
+ setMargin(PageMargin.getByShortValue(margin), size);
+ }
+
+ /**
+ * Sets the size of the margin in inches.
+ *
+ * @param margin which margin to set
+ * @param size the size of the margin
+ * @since POI 5.2.3
+ */
+ @Override
+ public void setMargin(PageMargin margin, double size) {
CTPageMargins pageMargins = worksheet.isSetPageMargins() ?
worksheet.getPageMargins() : worksheet.addNewPageMargins();
switch (margin) {
- case LeftMargin:
+ case LEFT:
pageMargins.setLeft(size);
break;
- case RightMargin:
+ case RIGHT:
pageMargins.setRight(size);
break;
- case TopMargin:
+ case TOP:
pageMargins.setTop(size);
break;
- case BottomMargin:
+ case BOTTOM:
pageMargins.setBottom(size);
break;
- case HeaderMargin:
+ case HEADER:
pageMargins.setHeader(size);
break;
- case FooterMargin:
+ case FOOTER:
pageMargins.setFooter(size);
break;
default :
diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
index e9f6377402..c94c35e6e8 100644
--- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
+++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
@@ -1341,20 +1341,41 @@ public final class HSSFSheet implements Sheet {
/**
* Sets the size of the margin in inches.
*
- * @param margin which margin to get
- * @param size the size of the margin
+ * @param margin which margin to set
+ * @param size the size of the margin
+ * @see Sheet#LeftMargin
+ * @see Sheet#RightMargin
+ * @see Sheet#TopMargin
+ * @see Sheet#BottomMargin
+ * @see Sheet#HeaderMargin
+ * @see Sheet#FooterMargin
+ * @deprecated use {@link #setMargin(PageMargin, double)} instead
*/
@Override
+ @Deprecated
+ @Removal(version = "7.0.0")
public void setMargin(short margin, double size) {
+ setMargin(PageMargin.getByShortValue(margin), size);
+ }
+
+ /**
+ * Sets the size of the margin in inches.
+ *
+ * @param margin which margin to set
+ * @param size the size of the margin
+ * @since POI 5.2.3
+ */
+ @Override
+ public void setMargin(PageMargin margin, double size) {
switch (margin) {
- case FooterMargin:
+ case FOOTER:
_sheet.getPageSettings().getPrintSetup().setFooterMargin(size);
break;
- case HeaderMargin:
+ case HEADER:
_sheet.getPageSettings().getPrintSetup().setHeaderMargin(size);
break;
default:
- _sheet.getPageSettings().setMargin(margin, size);
+ _sheet.getPageSettings().setMargin(margin.getLegacyApiValue(), size);
}
}
diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/Sheet.java b/poi/src/main/java/org/apache/poi/ss/usermodel/Sheet.java
index 5899795817..f3141a8162 100644
--- a/poi/src/main/java/org/apache/poi/ss/usermodel/Sheet.java
+++ b/poi/src/main/java/org/apache/poi/ss/usermodel/Sheet.java
@@ -642,12 +642,24 @@ public interface Sheet extends Iterable<Row> {
/**
* Sets the size of the margin in inches.
*
- * @param margin which margin to get
+ * @param margin which margin to set
* @param size the size of the margin
+ * @deprecated use {@link #setMargin(PageMargin, double)} instead
*/
+ @Deprecated
+ @Removal(version = "7.0.0")
void setMargin(short margin, double size);
/**
+ * Sets the size of the margin in inches.
+ *
+ * @param margin which margin to set
+ * @param size the size of the margin
+ * @since POI 5.2.3
+ */
+ void setMargin(PageMargin margin, double size);
+
+ /**
* Answer whether protection is enabled or disabled
*
* @return true =&gt; protection enabled; false =&gt; protection disabled