summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Woolsey <gwoolsey@apache.org>2017-05-31 00:22:58 +0000
committerGreg Woolsey <gwoolsey@apache.org>2017-05-31 00:22:58 +0000
commit7715c9bb367bfd19e3f111757544a4cfca911fed (patch)
tree94d9d09be2ba57067e69fb16cf47ffdf3b9d4099
parent4e57326803ebf9febc5e01a6c1129948121ad171 (diff)
downloadpoi-7715c9bb367bfd19e3f111757544a4cfca911fed.tar.gz
poi-7715c9bb367bfd19e3f111757544a4cfca911fed.zip
#61085 support table styles
Needed a bit more, to support table/range only border properties for "internal" vertical and horizontal borders. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1796961 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java97
-rw-r--r--src/java/org/apache/poi/ss/usermodel/BorderFormatting.java80
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java156
3 files changed, 288 insertions, 45 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
index c4113b6159..a78e323fa8 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
@@ -20,6 +20,7 @@ package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Color;
@@ -364,4 +365,100 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
setTopBorderColor(hcolor.getIndex());
}
}
+
+ /**
+ * HSSF doesn't support table borders, so always {@link BorderStyle#NONE}
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#getBorderVerticalEnum()
+ */
+ public BorderStyle getBorderVerticalEnum() {
+ return BorderStyle.NONE;
+ }
+
+ /**
+ * HSSF doesn't support table borders, so always {@link BorderStyle#NONE}
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#getBorderHorizontalEnum()
+ */
+ public BorderStyle getBorderHorizontalEnum() {
+ return BorderStyle.NONE;
+ }
+
+ /**
+ * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#getVerticalBorderColor()
+ */
+ public short getVerticalBorderColor() {
+ return HSSFColorPredefined.AUTOMATIC.getIndex();
+ }
+
+ /**
+ * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#getVerticalBorderColorColor()
+ */
+ public Color getVerticalBorderColorColor() {
+ return HSSFColorPredefined.AUTOMATIC.getColor();
+ }
+
+ /**
+ * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#getHorizontalBorderColor()
+ */
+ public short getHorizontalBorderColor() {
+ return HSSFColorPredefined.AUTOMATIC.getIndex();
+ }
+
+ /**
+ * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#getHorizontalBorderColorColor()
+ */
+ public Color getHorizontalBorderColorColor() {
+ return HSSFColorPredefined.AUTOMATIC.getColor();
+ }
+
+ /**
+ * Not available for HSSF.
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#setBorderHorizontal(org.apache.poi.ss.usermodel.BorderStyle)
+ */
+ public void setBorderHorizontal(BorderStyle border) {
+ // nothing
+ }
+
+ /**
+ * Not available for HSSF.
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#setBorderVertical(org.apache.poi.ss.usermodel.BorderStyle)
+ */
+ public void setBorderVertical(BorderStyle border) {
+ // nothing
+ }
+
+ /**
+ * Not available for HSSF.
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#setHorizontalBorderColor(short)
+ */
+ public void setHorizontalBorderColor(short color) {
+ // nothing
+ }
+
+ /**
+ * Not available for HSSF.
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#setHorizontalBorderColor(org.apache.poi.ss.usermodel.Color)
+ */
+ public void setHorizontalBorderColor(Color color) {
+ // nothing
+ }
+
+ /**
+ * Not available for HSSF.
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#setVerticalBorderColor(short)
+ */
+ public void setVerticalBorderColor(short color) {
+ // nothing
+ }
+
+ /**
+ * Not available for HSSF.
+ * @see org.apache.poi.ss.usermodel.BorderFormatting#setVerticalBorderColor(org.apache.poi.ss.usermodel.Color)
+ */
+ public void setVerticalBorderColor(Color color) {
+ // nothing
+ }
}
diff --git a/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java b/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java
index da8aabdfa6..030a33d5a9 100644
--- a/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java
+++ b/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java
@@ -150,6 +150,18 @@ public interface BorderFormatting {
/** @since POI 3.15 */
BorderStyle getBorderTopEnum();
+ /**
+ * Only valid for range borders, such as table styles
+ * @since 3.17 beta 1
+ * @return border style
+ */
+ BorderStyle getBorderVerticalEnum();
+ /**
+ * Only valid for range borders, such as table styles
+ * @since 3.17 beta 1
+ * @return border style
+ */
+ BorderStyle getBorderHorizontalEnum();
short getBottomBorderColor();
Color getBottomBorderColorColor();
@@ -167,6 +179,32 @@ public interface BorderFormatting {
Color getTopBorderColorColor();
/**
+ * Range internal borders. Only relevant for range styles, such as table formatting
+ * @since 3.17 beta 1
+ * @return color index
+ */
+ short getVerticalBorderColor();
+ /**
+ * Range internal borders. Only relevant for range styles, such as table formatting
+ * @since 3.17 beta 1
+ * @return color
+ */
+ Color getVerticalBorderColorColor();
+
+ /**
+ * Range internal borders. Only relevant for range styles, such as table formatting
+ * @since 3.17 beta 1
+ * @return color index
+ */
+ short getHorizontalBorderColor();
+ /**
+ * Range internal borders. Only relevant for range styles, such as table formatting
+ * @since 3.17 beta 1
+ * @return color
+ */
+ Color getHorizontalBorderColorColor();
+
+ /**
* Set bottom border.
*
* @param border MUST be a BORDER_* constant
@@ -240,6 +278,22 @@ public interface BorderFormatting {
* @param border
*/
void setBorderTop(BorderStyle border);
+
+ /**
+ * Set range internal horizontal borders.
+ *
+ * @since 3.17 beta 1
+ * @param border
+ */
+ void setBorderHorizontal(BorderStyle border);
+
+ /**
+ * Set range internal vertical borders.
+ *
+ * @since 3.17 beta 1
+ * @param border
+ */
+ void setBorderVertical(BorderStyle border);
void setBottomBorderColor(short color);
void setBottomBorderColor(Color color);
@@ -255,4 +309,30 @@ public interface BorderFormatting {
void setTopBorderColor(short color);
void setTopBorderColor(Color color);
+
+ /**
+ * Range internal border color, such as table styles
+ * @since 3.17 beta 1
+ * @param color index
+ */
+ void setHorizontalBorderColor(short color);
+ /**
+ * Range internal border color, such as table styles
+ * @since 3.17 beta 1
+ * @param color index
+ */
+ void setHorizontalBorderColor(Color color);
+
+ /**
+ * Range internal border color, such as table styles
+ * @since 3.17 beta 1
+ * @param color index
+ */
+ void setVerticalBorderColor(short color);
+ /**
+ * Range internal border color, such as table styles
+ * @since 3.17 beta 1
+ * @param color index
+ */
+ void setVerticalBorderColor(Color color);
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java
index 621e9434f6..029729a4a2 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java
@@ -50,8 +50,7 @@ public class XSSFBorderFormatting implements BorderFormatting {
*/
@Override
public BorderStyle getBorderBottomEnum() {
- STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle() : null;
- return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
+ return getBorderStyle(_border.getBottom());
}
/**
@@ -67,8 +66,7 @@ public class XSSFBorderFormatting implements BorderFormatting {
*/
@Override
public BorderStyle getBorderDiagonalEnum() {
- STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle() : null;
- return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
+ return getBorderStyle(_border.getDiagonal());
}
/**
@@ -84,8 +82,7 @@ public class XSSFBorderFormatting implements BorderFormatting {
*/
@Override
public BorderStyle getBorderLeftEnum() {
- STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null;
- return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
+ return getBorderStyle(_border.getLeft());
}
/**
@@ -101,8 +98,7 @@ public class XSSFBorderFormatting implements BorderFormatting {
*/
@Override
public BorderStyle getBorderRightEnum() {
- STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() : null;
- return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
+ return getBorderStyle(_border.getRight());
}
/**
@@ -118,78 +114,52 @@ public class XSSFBorderFormatting implements BorderFormatting {
*/
@Override
public BorderStyle getBorderTopEnum() {
- STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null;
- return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
+ return getBorderStyle(_border.getTop());
}
@Override
public XSSFColor getBottomBorderColorColor() {
- if(!_border.isSetBottom()) return null;
-
- CTBorderPr pr = _border.getBottom();
- return new XSSFColor(pr.getColor(), _colorMap);
+ return getColor(_border.getBottom());
}
@Override
public short getBottomBorderColor() {
- XSSFColor color = getBottomBorderColorColor();
- if (color == null) return 0;
- return color.getIndexed();
+ return getIndexedColor(getBottomBorderColorColor());
}
@Override
public XSSFColor getDiagonalBorderColorColor() {
- if(!_border.isSetDiagonal()) return null;
-
- CTBorderPr pr = _border.getDiagonal();
- return new XSSFColor(pr.getColor(), _colorMap);
+ return getColor(_border.getDiagonal());
}
@Override
public short getDiagonalBorderColor() {
- XSSFColor color = getDiagonalBorderColorColor();
- if (color == null) return 0;
- return color.getIndexed();
+ return getIndexedColor(getDiagonalBorderColorColor());
}
@Override
public XSSFColor getLeftBorderColorColor() {
- if(!_border.isSetLeft()) return null;
-
- CTBorderPr pr = _border.getLeft();
- return new XSSFColor(pr.getColor(), _colorMap);
+ return getColor(_border.getLeft());
}
@Override
public short getLeftBorderColor() {
- XSSFColor color = getLeftBorderColorColor();
- if (color == null) return 0;
- return color.getIndexed();
+ return getIndexedColor(getLeftBorderColorColor());
}
@Override
public XSSFColor getRightBorderColorColor() {
- if(!_border.isSetRight()) return null;
-
- CTBorderPr pr = _border.getRight();
- return new XSSFColor(pr.getColor(), _colorMap);
+ return getColor(_border.getRight());
}
@Override
public short getRightBorderColor() {
- XSSFColor color = getRightBorderColorColor();
- if (color == null) return 0;
- return color.getIndexed();
+ return getIndexedColor(getRightBorderColorColor());
}
@Override
public XSSFColor getTopBorderColorColor() {
- if(!_border.isSetTop()) return null;
-
- CTBorderPr pr = _border.getTop();
- return new XSSFColor(pr.getColor(), _colorMap);
+ return getColor(_border.getTop());
}
@Override
public short getTopBorderColor() {
- XSSFColor color = getRightBorderColorColor();
- if (color == null) return 0;
- return color.getIndexed();
+ return getIndexedColor(getRightBorderColorColor());
}
/**
@@ -366,4 +336,100 @@ public class XSSFBorderFormatting implements BorderFormatting {
pr.setColor(color);
}
}
+
+ public BorderStyle getBorderVerticalEnum() {
+ return getBorderStyle(_border.getVertical());
+ }
+
+ public BorderStyle getBorderHorizontalEnum() {
+ return getBorderStyle(_border.getHorizontal());
+ }
+
+ public short getVerticalBorderColor() {
+ return getIndexedColor(getVerticalBorderColorColor());
+ }
+
+ public XSSFColor getVerticalBorderColorColor() {
+ return getColor(_border.getVertical());
+ }
+
+ public short getHorizontalBorderColor() {
+ return getIndexedColor(getHorizontalBorderColorColor());
+ }
+
+ public XSSFColor getHorizontalBorderColorColor() {
+ return getColor(_border.getHorizontal());
+ }
+
+ public void setBorderHorizontal(BorderStyle border) {
+ CTBorderPr pr = _border.isSetHorizontal() ? _border.getHorizontal() : _border.addNewHorizontal();
+ if(border == BorderStyle.NONE) _border.unsetHorizontal();
+ else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
+ }
+
+ public void setBorderVertical(BorderStyle border) {
+ CTBorderPr pr = _border.isSetVertical() ? _border.getVertical() : _border.addNewVertical();
+ if(border == BorderStyle.NONE) _border.unsetVertical();
+ else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
+ }
+
+ public void setHorizontalBorderColor(short color) {
+ CTColor ctColor = CTColor.Factory.newInstance();
+ ctColor.setIndexed(color);
+ setHorizontalBorderColor(ctColor);
+ }
+
+ public void setHorizontalBorderColor(Color color) {
+ XSSFColor xcolor = XSSFColor.toXSSFColor(color);
+ if (xcolor == null) setBottomBorderColor((CTColor)null);
+ else setHorizontalBorderColor(xcolor.getCTColor());
+ }
+
+ public void setHorizontalBorderColor(CTColor color) {
+ CTBorderPr pr = _border.isSetHorizontal() ? _border.getHorizontal() : _border.addNewHorizontal();
+ if (color == null) {
+ pr.unsetColor();
+ } else {
+ pr.setColor(color);
+ }
+ }
+
+ public void setVerticalBorderColor(short color) {
+ CTColor ctColor = CTColor.Factory.newInstance();
+ ctColor.setIndexed(color);
+ setVerticalBorderColor(ctColor);
+ }
+
+ public void setVerticalBorderColor(Color color) {
+ XSSFColor xcolor = XSSFColor.toXSSFColor(color);
+ if (xcolor == null) setBottomBorderColor((CTColor)null);
+ else setVerticalBorderColor(xcolor.getCTColor());
+ }
+
+ public void setVerticalBorderColor(CTColor color) {
+ CTBorderPr pr = _border.isSetVertical() ? _border.getVertical() : _border.addNewVertical();
+ if (color == null) {
+ pr.unsetColor();
+ } else {
+ pr.setColor(color);
+ }
+ }
+
+ /**
+ * @param borderPr
+ * @return BorderStyle from the given element's style, or NONE if border is null
+ */
+ private BorderStyle getBorderStyle(CTBorderPr borderPr) {
+ if (borderPr == null) return BorderStyle.NONE;
+ STBorderStyle.Enum ptrn = borderPr.getStyle();
+ return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
+ }
+
+ private short getIndexedColor(XSSFColor color) {
+ return color == null ? 0 : color.getIndexed();
+ }
+
+ private XSSFColor getColor(CTBorderPr pr) {
+ return pr == null ? null : new XSSFColor(pr.getColor(), _colorMap);
+ }
}