mirror of https://github.com/apache/poi.git
#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
This commit is contained in:
parent
4e57326803
commit
7715c9bb36
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
@ -166,6 +178,32 @@ public interface BorderFormatting {
|
|||
short getTopBorderColor();
|
||||
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.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue