bug 59264: use BorderStyle for changing Cell border line style

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1737879 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-04-05 20:28:46 +00:00
parent 739196e5b3
commit 1786767b89
28 changed files with 984 additions and 686 deletions

View File

@ -22,7 +22,7 @@ import java.awt.*;
import javax.swing.border.AbstractBorder; import javax.swing.border.AbstractBorder;
import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.ss.usermodel.BorderStyle;
/** /**
* This is an attempt to implement Excel style borders for the SheetViewer. * This is an attempt to implement Excel style borders for the SheetViewer.
@ -37,10 +37,10 @@ public class SVBorder extends AbstractBorder {
private Color eastColor = null; private Color eastColor = null;
private Color southColor = null; private Color southColor = null;
private Color westColor = null; private Color westColor = null;
private int northBorderType = HSSFCellStyle.BORDER_NONE; private BorderStyle northBorderType = BorderStyle.NONE;
private int eastBorderType =HSSFCellStyle.BORDER_NONE; private BorderStyle eastBorderType = BorderStyle.NONE;
private int southBorderType = HSSFCellStyle.BORDER_NONE; private BorderStyle southBorderType = BorderStyle.NONE;
private int westBorderType = HSSFCellStyle.BORDER_NONE; private BorderStyle westBorderType = BorderStyle.NONE;
private boolean northBorder=false; private boolean northBorder=false;
private boolean eastBorder=false; private boolean eastBorder=false;
private boolean southBorder=false; private boolean southBorder=false;
@ -49,8 +49,8 @@ public class SVBorder extends AbstractBorder {
public void setBorder(Color northColor, Color eastColor, public void setBorder(Color northColor, Color eastColor,
Color southColor, Color westColor, Color southColor, Color westColor,
int northBorderType, int eastBorderType, BorderStyle northBorderType, BorderStyle eastBorderType,
int southBorderType, int westBorderType, BorderStyle southBorderType, BorderStyle westBorderType,
boolean selected) { boolean selected) {
this.eastColor = eastColor; this.eastColor = eastColor;
this.southColor = southColor; this.southColor = southColor;
@ -59,10 +59,10 @@ public class SVBorder extends AbstractBorder {
this.eastBorderType = eastBorderType; this.eastBorderType = eastBorderType;
this.southBorderType = southBorderType; this.southBorderType = southBorderType;
this.westBorderType = westBorderType; this.westBorderType = westBorderType;
this.northBorder=northBorderType != HSSFCellStyle.BORDER_NONE; this.northBorder=northBorderType != BorderStyle.NONE;
this.eastBorder=eastBorderType != HSSFCellStyle.BORDER_NONE; this.eastBorder=eastBorderType != BorderStyle.NONE;
this.southBorder=southBorderType != HSSFCellStyle.BORDER_NONE; this.southBorder=southBorderType != BorderStyle.NONE;
this.westBorder=westBorderType != HSSFCellStyle.BORDER_NONE; this.westBorder=westBorderType != BorderStyle.NONE;
this.selected = selected; this.selected = selected;
} }
@ -109,9 +109,9 @@ public class SVBorder extends AbstractBorder {
int height) { int height) {
if (northBorder && if (northBorder &&
((northBorderType == HSSFCellStyle.BORDER_THIN) || ((northBorderType == BorderStyle.THIN) ||
(northBorderType == HSSFCellStyle.BORDER_MEDIUM) || (northBorderType == BorderStyle.MEDIUM) ||
(northBorderType == HSSFCellStyle.BORDER_THICK) (northBorderType == BorderStyle.THICK)
) )
) { ) {
@ -125,9 +125,9 @@ public class SVBorder extends AbstractBorder {
} }
if (eastBorder && if (eastBorder &&
((eastBorderType == HSSFCellStyle.BORDER_THIN) || ((eastBorderType == BorderStyle.THIN) ||
(eastBorderType == HSSFCellStyle.BORDER_MEDIUM) || (eastBorderType == BorderStyle.MEDIUM) ||
(eastBorderType == HSSFCellStyle.BORDER_THICK) (eastBorderType == BorderStyle.THICK)
) )
) { ) {
@ -141,9 +141,9 @@ public class SVBorder extends AbstractBorder {
} }
if (southBorder && if (southBorder &&
((southBorderType == HSSFCellStyle.BORDER_THIN) || ((southBorderType == BorderStyle.THIN) ||
(southBorderType == HSSFCellStyle.BORDER_MEDIUM) || (southBorderType == BorderStyle.MEDIUM) ||
(southBorderType == HSSFCellStyle.BORDER_THICK) (southBorderType == BorderStyle.THICK)
) )
) { ) {
@ -156,9 +156,9 @@ public class SVBorder extends AbstractBorder {
} }
if (westBorder && if (westBorder &&
((westBorderType == HSSFCellStyle.BORDER_THIN) || ((westBorderType == BorderStyle.THIN) ||
(westBorderType == HSSFCellStyle.BORDER_MEDIUM) || (westBorderType == BorderStyle.MEDIUM) ||
(westBorderType == HSSFCellStyle.BORDER_THICK) (westBorderType == BorderStyle.THICK)
) )
) { ) {
@ -179,7 +179,7 @@ public class SVBorder extends AbstractBorder {
private void paintDottedBorders(Graphics g, int x, int y, int width, private void paintDottedBorders(Graphics g, int x, int y, int width,
int height) { int height) {
if (northBorder && if (northBorder &&
northBorderType == HSSFCellStyle.BORDER_DOTTED) { northBorderType == BorderStyle.DOTTED) {
int thickness = getThickness(northBorderType); int thickness = getThickness(northBorderType);
g.setColor(northColor); g.setColor(northColor);
@ -192,7 +192,7 @@ public class SVBorder extends AbstractBorder {
} }
if (eastBorder && if (eastBorder &&
eastBorderType == HSSFCellStyle.BORDER_DOTTED eastBorderType == BorderStyle.DOTTED
) { ) {
int thickness = getThickness(eastBorderType); int thickness = getThickness(eastBorderType);
@ -208,7 +208,7 @@ public class SVBorder extends AbstractBorder {
} }
if (southBorder && if (southBorder &&
southBorderType == HSSFCellStyle.BORDER_DOTTED southBorderType == BorderStyle.DOTTED
) { ) {
int thickness = getThickness(southBorderType); int thickness = getThickness(southBorderType);
@ -222,7 +222,7 @@ public class SVBorder extends AbstractBorder {
} }
if (westBorder && if (westBorder &&
westBorderType == HSSFCellStyle.BORDER_DOTTED westBorderType == BorderStyle.DOTTED
) { ) {
int thickness = getThickness(westBorderType); int thickness = getThickness(westBorderType);
@ -245,14 +245,14 @@ public class SVBorder extends AbstractBorder {
private void paintDashedBorders(Graphics g, int x, int y, int width, private void paintDashedBorders(Graphics g, int x, int y, int width,
int height) { int height) {
if (northBorder && if (northBorder &&
((northBorderType == HSSFCellStyle.BORDER_DASHED) || ((northBorderType == BorderStyle.DASHED) ||
(northBorderType == HSSFCellStyle.BORDER_HAIR)) (northBorderType == BorderStyle.HAIR))
) { ) {
int thickness = getThickness(northBorderType); int thickness = getThickness(northBorderType);
int dashlength = 1; int dashlength = 1;
if (northBorderType == HSSFCellStyle.BORDER_DASHED) if (northBorderType == BorderStyle.DASHED)
dashlength = 2; dashlength = 2;
g.setColor(northColor); g.setColor(northColor);
@ -265,8 +265,8 @@ public class SVBorder extends AbstractBorder {
} }
if (eastBorder && if (eastBorder &&
((eastBorderType == HSSFCellStyle.BORDER_DASHED) || ((eastBorderType == BorderStyle.DASHED) ||
(eastBorderType == HSSFCellStyle.BORDER_HAIR)) (eastBorderType == BorderStyle.HAIR))
) { ) {
int thickness = getThickness(eastBorderType); int thickness = getThickness(eastBorderType);
@ -275,7 +275,7 @@ public class SVBorder extends AbstractBorder {
int dashlength = 1; int dashlength = 1;
if (eastBorderType == HSSFCellStyle.BORDER_DASHED) if (eastBorderType == BorderStyle.DASHED)
dashlength = 2; dashlength = 2;
g.setColor(eastColor); g.setColor(eastColor);
@ -288,8 +288,8 @@ public class SVBorder extends AbstractBorder {
} }
if (southBorder && if (southBorder &&
((southBorderType == HSSFCellStyle.BORDER_DASHED) || ((southBorderType == BorderStyle.DASHED) ||
(southBorderType == HSSFCellStyle.BORDER_HAIR)) (southBorderType == BorderStyle.HAIR))
) { ) {
int thickness = getThickness(southBorderType); int thickness = getThickness(southBorderType);
@ -297,7 +297,7 @@ public class SVBorder extends AbstractBorder {
int dashlength = 1; int dashlength = 1;
if (southBorderType == HSSFCellStyle.BORDER_DASHED) if (southBorderType == BorderStyle.DASHED)
dashlength = 2; dashlength = 2;
g.setColor(southColor); g.setColor(southColor);
@ -309,8 +309,8 @@ public class SVBorder extends AbstractBorder {
} }
if (westBorder && if (westBorder &&
((westBorderType == HSSFCellStyle.BORDER_DASHED) || ((westBorderType == BorderStyle.DASHED) ||
(westBorderType == HSSFCellStyle.BORDER_HAIR)) (westBorderType == BorderStyle.HAIR))
) { ) {
int thickness = getThickness(westBorderType); int thickness = getThickness(westBorderType);
@ -318,7 +318,7 @@ public class SVBorder extends AbstractBorder {
int dashlength = 1; int dashlength = 1;
if (westBorderType == HSSFCellStyle.BORDER_DASHED) if (westBorderType == BorderStyle.DASHED)
dashlength = 2; dashlength = 2;
g.setColor(westColor); g.setColor(westColor);
@ -338,7 +338,7 @@ public class SVBorder extends AbstractBorder {
private void paintDoubleBorders(Graphics g, int x, int y, int width, private void paintDoubleBorders(Graphics g, int x, int y, int width,
int height) { int height) {
if (northBorder && if (northBorder &&
northBorderType == HSSFCellStyle.BORDER_DOUBLE) { northBorderType == BorderStyle.DOUBLE) {
g.setColor(northColor); g.setColor(northColor);
@ -358,7 +358,7 @@ public class SVBorder extends AbstractBorder {
} }
if (eastBorder && if (eastBorder &&
eastBorderType == HSSFCellStyle.BORDER_DOUBLE eastBorderType == BorderStyle.DOUBLE
) { ) {
int thickness = getThickness(eastBorderType); int thickness = getThickness(eastBorderType);
@ -380,7 +380,7 @@ public class SVBorder extends AbstractBorder {
} }
if (southBorder && if (southBorder &&
southBorderType == HSSFCellStyle.BORDER_DOUBLE southBorderType == BorderStyle.DOUBLE
) { ) {
g.setColor(southColor); g.setColor(southColor);
@ -400,7 +400,7 @@ public class SVBorder extends AbstractBorder {
} }
if (westBorder && if (westBorder &&
westBorderType == HSSFCellStyle.BORDER_DOUBLE westBorderType == BorderStyle.DOUBLE
) { ) {
int thickness = getThickness(westBorderType); int thickness = getThickness(westBorderType);
@ -429,8 +429,8 @@ public class SVBorder extends AbstractBorder {
private void paintDashDotDotBorders(Graphics g, int x, int y, int width, private void paintDashDotDotBorders(Graphics g, int x, int y, int width,
int height) { int height) {
if (northBorder && if (northBorder &&
((northBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || ((northBorderType == BorderStyle.DASH_DOT_DOT) ||
(northBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) (northBorderType == BorderStyle.MEDIUM_DASH_DOT_DOT))
) { ) {
int thickness = getThickness(northBorderType); int thickness = getThickness(northBorderType);
@ -442,8 +442,8 @@ public class SVBorder extends AbstractBorder {
} }
if (eastBorder && if (eastBorder &&
((eastBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || ((eastBorderType == BorderStyle.DASH_DOT_DOT) ||
(eastBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) (eastBorderType == BorderStyle.MEDIUM_DASH_DOT_DOT))
) { ) {
int thickness = getThickness(eastBorderType); int thickness = getThickness(eastBorderType);
@ -457,8 +457,8 @@ public class SVBorder extends AbstractBorder {
} }
if (southBorder && if (southBorder &&
((southBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || ((southBorderType == BorderStyle.DASH_DOT_DOT) ||
(southBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) (southBorderType == BorderStyle.MEDIUM_DASH_DOT_DOT))
) { ) {
int thickness = getThickness(southBorderType); int thickness = getThickness(southBorderType);
@ -472,8 +472,8 @@ public class SVBorder extends AbstractBorder {
} }
if (westBorder && if (westBorder &&
((westBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || ((westBorderType == BorderStyle.DASH_DOT_DOT) ||
(westBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) (westBorderType == BorderStyle.MEDIUM_DASH_DOT_DOT))
) { ) {
int thickness = getThickness(westBorderType); int thickness = getThickness(westBorderType);
@ -530,34 +530,22 @@ public class SVBorder extends AbstractBorder {
/** /**
* @returns the line thickness for a border based on border type * @returns the line thickness for a border based on border type
*/ */
private int getThickness(int thickness) { private int getThickness(BorderStyle thickness) {
int retval=1;
switch (thickness) { switch (thickness) {
case HSSFCellStyle.BORDER_THIN: case DASH_DOT_DOT:
retval=2; case DASHED:
break; case HAIR:
case HSSFCellStyle.BORDER_MEDIUM: return 1;
retval=3; case THIN:
break; return 2;
case HSSFCellStyle.BORDER_THICK: case MEDIUM:
retval=4; case MEDIUM_DASH_DOT_DOT:
break; return 3;
case HSSFCellStyle.BORDER_DASHED: case THICK:
retval=1; return 4;
break;
case HSSFCellStyle.BORDER_DASH_DOT_DOT:
retval=1;
break;
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT:
retval=3;
break;
case HSSFCellStyle.BORDER_HAIR:
retval=1;
break;
default: default:
retval=1; return 1;
} }
return retval;
} }

View File

@ -26,11 +26,11 @@ import javax.swing.border.*;
import java.awt.Component; import java.awt.Component;
import java.awt.Color; import java.awt.Color;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.io.Serializable; import java.io.Serializable;
import java.text.*; import java.text.*;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.BorderStyle;
/** /**
@ -224,10 +224,10 @@ public class SVTableCellRenderer extends JLabel
SVTableUtils.black, SVTableUtils.black,
SVTableUtils.black, SVTableUtils.black,
SVTableUtils.black, SVTableUtils.black,
HSSFCellStyle.BORDER_NONE, BorderStyle.NONE,
HSSFCellStyle.BORDER_NONE, BorderStyle.NONE,
HSSFCellStyle.BORDER_NONE, BorderStyle.NONE,
HSSFCellStyle.BORDER_NONE, BorderStyle.NONE,
isSelected); isSelected);
setBorder(cellBorder); setBorder(cellBorder);
} }

View File

@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Color; import org.apache.poi.ss.usermodel.Color;
import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.DateUtil;
@ -362,23 +363,23 @@ public class ExcelComparator {
String borderName; String borderName;
switch (borderSide) { switch (borderSide) {
case 't': default: case 't': default:
b1 = style1.getBorderTop() == 1; b1 = style1.getBorderTop() == BorderStyle.THIN;
b2 = style2.getBorderTop() == 1; b2 = style2.getBorderTop() == BorderStyle.THIN;
borderName = "TOP"; borderName = "TOP";
break; break;
case 'b': case 'b':
b1 = style1.getBorderBottom() == 1; b1 = style1.getBorderBottom() == BorderStyle.THIN;
b2 = style2.getBorderBottom() == 1; b2 = style2.getBorderBottom() == BorderStyle.THIN;
borderName = "BOTTOM"; borderName = "BOTTOM";
break; break;
case 'l': case 'l':
b1 = style1.getBorderLeft() == 1; b1 = style1.getBorderLeft() == BorderStyle.THIN;
b2 = style2.getBorderLeft() == 1; b2 = style2.getBorderLeft() == BorderStyle.THIN;
borderName = "LEFT"; borderName = "LEFT";
break; break;
case 'r': case 'r':
b1 = style1.getBorderRight() == 1; b1 = style1.getBorderRight() == BorderStyle.THIN;
b2 = style2.getBorderRight() == 1; b2 = style2.getBorderRight() == BorderStyle.THIN;
borderName = "RIGHT"; borderName = "RIGHT";
break; break;
} }

View File

@ -62,22 +62,34 @@ public class ToHtml {
private static final String COL_HEAD_CLASS = "colHeader"; private static final String COL_HEAD_CLASS = "colHeader";
private static final String ROW_HEAD_CLASS = "rowHeader"; private static final String ROW_HEAD_CLASS = "rowHeader";
private static final Map<Short, String> ALIGN = mapFor(ALIGN_LEFT, "left", private static final Map<Short, String> ALIGN = mapFor(
ALIGN_CENTER, "center", ALIGN_RIGHT, "right", ALIGN_FILL, "left", ALIGN_LEFT, "left",
ALIGN_JUSTIFY, "left", ALIGN_CENTER_SELECTION, "center"); ALIGN_CENTER, "center",
ALIGN_RIGHT, "right",
ALIGN_FILL, "left",
ALIGN_JUSTIFY, "left",
ALIGN_CENTER_SELECTION, "center");
private static final Map<Short, String> VERTICAL_ALIGN = mapFor( private static final Map<Short, String> VERTICAL_ALIGN = mapFor(
VERTICAL_BOTTOM, "bottom", VERTICAL_CENTER, "middle", VERTICAL_TOP, VERTICAL_BOTTOM, "bottom",
"top"); VERTICAL_CENTER, "middle",
VERTICAL_TOP, "top");
private static final Map<Short, String> BORDER = mapFor(BORDER_DASH_DOT, private static final Map<BorderStyle, String> BORDER = mapFor(
"dashed 1pt", BORDER_DASH_DOT_DOT, "dashed 1pt", BORDER_DASHED, BorderStyle.DASH_DOT, "dashed 1pt",
"dashed 1pt", BORDER_DOTTED, "dotted 1pt", BORDER_DOUBLE, BorderStyle.DASH_DOT_DOT, "dashed 1pt",
"double 3pt", BORDER_HAIR, "solid 1px", BORDER_MEDIUM, "solid 2pt", BorderStyle.DASHED, "dashed 1pt",
BORDER_MEDIUM_DASH_DOT, "dashed 2pt", BORDER_MEDIUM_DASH_DOT_DOT, BorderStyle.DOTTED, "dotted 1pt",
"dashed 2pt", BORDER_MEDIUM_DASHED, "dashed 2pt", BORDER_NONE, BorderStyle.DOUBLE, "double 3pt",
"none", BORDER_SLANTED_DASH_DOT, "dashed 2pt", BORDER_THICK, BorderStyle.HAIR, "solid 1px",
"solid 3pt", BORDER_THIN, "dashed 1pt"); BorderStyle.MEDIUM, "solid 2pt",
BorderStyle.MEDIUM_DASH_DOT, "dashed 2pt",
BorderStyle.MEDIUM_DASH_DOT_DOT, "dashed 2pt",
BorderStyle.MEDIUM_DASHED, "dashed 2pt",
BorderStyle.NONE, "none",
BorderStyle.SLANTED_DASH_DOT, "dashed 2pt",
BorderStyle.THICK, "solid 3pt",
BorderStyle.THIN, "dashed 1pt");
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
private static <K, V> Map<K, V> mapFor(Object... mapping) { private static <K, V> Map<K, V> mapFor(Object... mapping) {

View File

@ -20,6 +20,7 @@ package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.record.CFRuleBase; import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.cf.BorderFormatting; import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Color; import org.apache.poi.ss.usermodel.Color;
/** /**
@ -41,65 +42,80 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
return borderFormatting; return borderFormatting;
} }
public short getBorderBottom() { @Override
return (short)borderFormatting.getBorderBottom(); public BorderStyle getBorderBottom() {
return BorderStyle.valueOf((short)borderFormatting.getBorderBottom());
} }
public short getBorderDiagonal() { @Override
return (short)borderFormatting.getBorderDiagonal(); public BorderStyle getBorderDiagonal() {
return BorderStyle.valueOf((short)borderFormatting.getBorderDiagonal());
} }
public short getBorderLeft() { @Override
return (short)borderFormatting.getBorderLeft(); public BorderStyle getBorderLeft() {
return BorderStyle.valueOf((short)borderFormatting.getBorderLeft());
} }
public short getBorderRight() { @Override
return (short)borderFormatting.getBorderRight(); public BorderStyle getBorderRight() {
return BorderStyle.valueOf((short)borderFormatting.getBorderRight());
} }
public short getBorderTop() { @Override
return (short)borderFormatting.getBorderTop(); public BorderStyle getBorderTop() {
return BorderStyle.valueOf((short)borderFormatting.getBorderTop());
} }
@Override
public short getBottomBorderColor() { public short getBottomBorderColor() {
return (short)borderFormatting.getBottomBorderColor(); return (short)borderFormatting.getBottomBorderColor();
} }
@Override
public HSSFColor getBottomBorderColorColor() { public HSSFColor getBottomBorderColorColor() {
return workbook.getCustomPalette().getColor( return workbook.getCustomPalette().getColor(
borderFormatting.getBottomBorderColor() borderFormatting.getBottomBorderColor()
); );
} }
@Override
public short getDiagonalBorderColor() { public short getDiagonalBorderColor() {
return (short)borderFormatting.getDiagonalBorderColor(); return (short)borderFormatting.getDiagonalBorderColor();
} }
@Override
public HSSFColor getDiagonalBorderColorColor() { public HSSFColor getDiagonalBorderColorColor() {
return workbook.getCustomPalette().getColor( return workbook.getCustomPalette().getColor(
borderFormatting.getDiagonalBorderColor() borderFormatting.getDiagonalBorderColor()
); );
} }
@Override
public short getLeftBorderColor() { public short getLeftBorderColor() {
return (short)borderFormatting.getLeftBorderColor(); return (short)borderFormatting.getLeftBorderColor();
} }
@Override
public HSSFColor getLeftBorderColorColor() { public HSSFColor getLeftBorderColorColor() {
return workbook.getCustomPalette().getColor( return workbook.getCustomPalette().getColor(
borderFormatting.getLeftBorderColor() borderFormatting.getLeftBorderColor()
); );
} }
@Override
public short getRightBorderColor() { public short getRightBorderColor() {
return (short)borderFormatting.getRightBorderColor(); return (short)borderFormatting.getRightBorderColor();
} }
@Override
public HSSFColor getRightBorderColorColor() { public HSSFColor getRightBorderColorColor() {
return workbook.getCustomPalette().getColor( return workbook.getCustomPalette().getColor(
borderFormatting.getRightBorderColor() borderFormatting.getRightBorderColor()
); );
} }
@Override
public short getTopBorderColor() { public short getTopBorderColor() {
return (short)borderFormatting.getTopBorderColor(); return (short)borderFormatting.getTopBorderColor();
} }
@Override
public HSSFColor getTopBorderColorColor() { public HSSFColor getTopBorderColorColor() {
return workbook.getCustomPalette().getColor( return workbook.getCustomPalette().getColor(
borderFormatting.getTopBorderColor() borderFormatting.getTopBorderColor()
@ -126,6 +142,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
} }
} }
@Override
public void setBorderBottom(short border) { public void setBorderBottom(short border) {
borderFormatting.setBorderBottom(border); borderFormatting.setBorderBottom(border);
if (border != 0) { if (border != 0) {
@ -134,7 +151,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setBottomBorderModified(false); cfRuleRecord.setBottomBorderModified(false);
} }
} }
@Override
public void setBorderBottom(BorderStyle border) {
setBorderBottom(border.getCode());
}
@Override
public void setBorderDiagonal(short border) { public void setBorderDiagonal(short border) {
borderFormatting.setBorderDiagonal(border); borderFormatting.setBorderDiagonal(border);
if (border != 0) { if (border != 0) {
@ -145,7 +167,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopLeftBottomRightBorderModified(false); cfRuleRecord.setTopLeftBottomRightBorderModified(false);
} }
} }
@Override
public void setBorderDiagonal(BorderStyle border) {
setBorderDiagonal(border.getCode());
}
@Override
public void setBorderLeft(short border) { public void setBorderLeft(short border) {
borderFormatting.setBorderLeft(border); borderFormatting.setBorderLeft(border);
if (border != 0) { if (border != 0) {
@ -154,7 +181,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setLeftBorderModified(false); cfRuleRecord.setLeftBorderModified(false);
} }
} }
@Override
public void setBorderLeft(BorderStyle border) {
setBorderLeft(border.getCode());
}
@Override
public void setBorderRight(short border) { public void setBorderRight(short border) {
borderFormatting.setBorderRight(border); borderFormatting.setBorderRight(border);
if (border != 0) { if (border != 0) {
@ -163,7 +195,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setRightBorderModified(false); cfRuleRecord.setRightBorderModified(false);
} }
} }
@Override
public void setBorderRight(BorderStyle border) {
setBorderRight(border.getCode());
}
@Override
public void setBorderTop(short border) { public void setBorderTop(short border) {
borderFormatting.setBorderTop(border); borderFormatting.setBorderTop(border);
if (border != 0) { if (border != 0) {
@ -172,7 +209,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopBorderModified(false); cfRuleRecord.setTopBorderModified(false);
} }
} }
@Override
public void setBorderTop(BorderStyle border) {
setBorderTop(border.getCode());
}
@Override
public void setBottomBorderColor(short color) { public void setBottomBorderColor(short color) {
borderFormatting.setBottomBorderColor(color); borderFormatting.setBottomBorderColor(color);
if (color != 0) { if (color != 0) {
@ -190,6 +232,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
} }
} }
@Override
public void setDiagonalBorderColor(short color) { public void setDiagonalBorderColor(short color) {
borderFormatting.setDiagonalBorderColor(color); borderFormatting.setDiagonalBorderColor(color);
if (color != 0) { if (color != 0) {
@ -200,6 +243,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopLeftBottomRightBorderModified(false); cfRuleRecord.setTopLeftBottomRightBorderModified(false);
} }
} }
@Override
public void setDiagonalBorderColor(Color color) { public void setDiagonalBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color); HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) { if (hcolor == null) {
@ -209,6 +253,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
} }
} }
@Override
public void setLeftBorderColor(short color) { public void setLeftBorderColor(short color) {
borderFormatting.setLeftBorderColor(color); borderFormatting.setLeftBorderColor(color);
if (color != 0) { if (color != 0) {
@ -217,6 +262,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setLeftBorderModified(false); cfRuleRecord.setLeftBorderModified(false);
} }
} }
@Override
public void setLeftBorderColor(Color color) { public void setLeftBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color); HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) { if (hcolor == null) {
@ -226,6 +272,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
} }
} }
@Override
public void setRightBorderColor(short color) { public void setRightBorderColor(short color) {
borderFormatting.setRightBorderColor(color); borderFormatting.setRightBorderColor(color);
if (color != 0) { if (color != 0) {
@ -234,6 +281,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setRightBorderModified(false); cfRuleRecord.setRightBorderModified(false);
} }
} }
@Override
public void setRightBorderColor(Color color) { public void setRightBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color); HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) { if (hcolor == null) {
@ -243,6 +291,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
} }
} }
@Override
public void setTopBorderColor(short color) { public void setTopBorderColor(short color) {
borderFormatting.setTopBorderColor(color); borderFormatting.setTopBorderColor(color);
if (color != 0) { if (color != 0) {
@ -251,6 +300,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopBorderModified(false); cfRuleRecord.setTopBorderModified(false);
} }
} }
@Override
public void setTopBorderColor(Color color) { public void setTopBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color); HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) { if (hcolor == null) {

View File

@ -26,6 +26,7 @@ import org.apache.poi.hssf.record.FontRecord;
import org.apache.poi.hssf.record.FormatRecord; import org.apache.poi.hssf.record.FormatRecord;
import org.apache.poi.hssf.record.StyleRecord; import org.apache.poi.hssf.record.StyleRecord;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
@ -410,6 +411,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_DASH_DOT_DOT * @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT * @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderLeft(short border) public void setBorderLeft(short border)
@ -417,29 +419,25 @@ public final class HSSFCellStyle implements CellStyle {
_format.setIndentNotParentBorder(true); _format.setIndentNotParentBorder(true);
_format.setBorderLeft(border); _format.setBorderLeft(border);
} }
/**
* set the type of border to use for the left border of the cell
* @param border type
*/
@Override
public void setBorderLeft(BorderStyle border)
{
setBorderLeft(border.getCode());
}
/** /**
* get the type of border to use for the left border of the cell * get the type of border to use for the left border of the cell
* @return border type * @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/ */
@Override @Override
public short getBorderLeft() public BorderStyle getBorderLeft()
{ {
return _format.getBorderLeft(); return BorderStyle.valueOf(_format.getBorderLeft());
} }
/** /**
@ -459,6 +457,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_DASH_DOT_DOT * @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT * @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderRight(short border) public void setBorderRight(short border)
@ -466,29 +465,25 @@ public final class HSSFCellStyle implements CellStyle {
_format.setIndentNotParentBorder(true); _format.setIndentNotParentBorder(true);
_format.setBorderRight(border); _format.setBorderRight(border);
} }
/**
* set the type of border to use for the right border of the cell
* @param border type
*/
@Override
public void setBorderRight(BorderStyle border)
{
setBorderRight(border.getCode());
}
/** /**
* get the type of border to use for the right border of the cell * get the type of border to use for the right border of the cell
* @return border type * @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/ */
@Override @Override
public short getBorderRight() public BorderStyle getBorderRight()
{ {
return _format.getBorderRight(); return BorderStyle.valueOf(_format.getBorderRight());
} }
/** /**
@ -508,6 +503,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_DASH_DOT_DOT * @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT * @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderTop(short border) public void setBorderTop(short border)
@ -515,29 +511,25 @@ public final class HSSFCellStyle implements CellStyle {
_format.setIndentNotParentBorder(true); _format.setIndentNotParentBorder(true);
_format.setBorderTop(border); _format.setBorderTop(border);
} }
/**
* set the type of border to use for the top border of the cell
* @param border type
*/
@Override
public void setBorderTop(BorderStyle border)
{
setBorderTop(border.getCode());
}
/** /**
* get the type of border to use for the top border of the cell * get the type of border to use for the top border of the cell
* @return border type * @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/ */
@Override @Override
public short getBorderTop() public BorderStyle getBorderTop()
{ {
return _format.getBorderTop(); return BorderStyle.valueOf(_format.getBorderTop());
} }
/** /**
@ -557,6 +549,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_DASH_DOT_DOT * @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT * @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderBottom(short border) public void setBorderBottom(short border)
@ -564,29 +557,25 @@ public final class HSSFCellStyle implements CellStyle {
_format.setIndentNotParentBorder(true); _format.setIndentNotParentBorder(true);
_format.setBorderBottom(border); _format.setBorderBottom(border);
} }
/**
* set the type of border to use for the bottom border of the cell
* @param border type
*/
@Override
public void setBorderBottom(BorderStyle border)
{
setBorderBottom(border.getCode());
}
/** /**
* get the type of border to use for the bottom border of the cell * get the type of border to use for the bottom border of the cell
* @return border type * @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/ */
@Override @Override
public short getBorderBottom() public BorderStyle getBorderBottom()
{ {
return _format.getBorderBottom(); return BorderStyle.valueOf(_format.getBorderBottom());
} }
/** /**

View File

@ -24,44 +24,86 @@ package org.apache.poi.ss.usermodel;
* of Conditional Formatting settings * of Conditional Formatting settings
*/ */
public interface BorderFormatting { public interface BorderFormatting {
/** No border */ /** No border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_NONE = 0x0; short BORDER_NONE = 0x0;
/** Thin border */
/** Thin border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_THIN = 0x1; short BORDER_THIN = 0x1;
/** Medium border */
/** Medium border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_MEDIUM = 0x2; short BORDER_MEDIUM = 0x2;
/** dash border */
/** dash border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_DASHED = 0x3; short BORDER_DASHED = 0x3;
/** dot border */
short BORDER_HAIR = 0x4; /** dot border
/** Thick border */ * @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_DOTTED = 0x4;
/** Thick border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_THICK = 0x5; short BORDER_THICK = 0x5;
/** double-line border */
/** double-line border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_DOUBLE = 0x6; short BORDER_DOUBLE = 0x6;
/** hair-line border */
short BORDER_DOTTED = 0x7; /** hair-line border
/** Medium dashed border */ * @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_HAIR = 0x7;
/** Medium dashed border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_MEDIUM_DASHED = 0x8; short BORDER_MEDIUM_DASHED = 0x8;
/** dash-dot border */
/** dash-dot border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_DASH_DOT = 0x9; short BORDER_DASH_DOT = 0x9;
/** medium dash-dot border */
/** medium dash-dot border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_MEDIUM_DASH_DOT = 0xA; short BORDER_MEDIUM_DASH_DOT = 0xA;
/** dash-dot-dot border */
/** dash-dot-dot border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_DASH_DOT_DOT = 0xB; short BORDER_DASH_DOT_DOT = 0xB;
/** medium dash-dot-dot border */
/** medium dash-dot-dot border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_MEDIUM_DASH_DOT_DOT = 0xC; short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
/** slanted dash-dot border */
/** slanted dash-dot border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_SLANTED_DASH_DOT = 0xD; short BORDER_SLANTED_DASH_DOT = 0xD;
short getBorderBottom(); BorderStyle getBorderBottom();
short getBorderDiagonal(); BorderStyle getBorderDiagonal();
short getBorderLeft(); BorderStyle getBorderLeft();
short getBorderRight(); BorderStyle getBorderRight();
short getBorderTop(); BorderStyle getBorderTop();
short getBottomBorderColor(); short getBottomBorderColor();
Color getBottomBorderColorColor(); Color getBottomBorderColorColor();
@ -78,35 +120,80 @@ public interface BorderFormatting {
short getTopBorderColor(); short getTopBorderColor();
Color getTopBorderColorColor(); Color getTopBorderColorColor();
/**
* Set bottom border.
*
* @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/
void setBorderBottom(short border); void setBorderBottom(short border);
/**
* Set bottom border.
*
* @param border
*/
void setBorderBottom(BorderStyle border);
/** /**
* Set diagonal border. * Set diagonal border.
* *
* @param border MUST be a BORDER_* constant * @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/ */
void setBorderDiagonal(short border); void setBorderDiagonal(short border);
/**
* Set diagonal border.
*
* @param border
*/
void setBorderDiagonal(BorderStyle border);
/** /**
* Set left border. * Set left border.
* *
* @param border MUST be a BORDER_* constant * @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/ */
void setBorderLeft(short border); void setBorderLeft(short border);
/**
* Set left border.
*
* @param border
*/
void setBorderLeft(BorderStyle border);
/** /**
* Set right border. * Set right border.
* *
* @param border MUST be a BORDER_* constant * @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/ */
void setBorderRight(short border); void setBorderRight(short border);
/**
* Set right border.
*
* @param border
*/
void setBorderRight(BorderStyle border);
/** /**
* Set top border. * Set top border.
* *
* @param border MUST be a BORDER_* constant * @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/ */
void setBorderTop(short border); void setBorderTop(short border);
/**
* Set top border.
*
* @param border
*/
void setBorderTop(BorderStyle border);
void setBottomBorderColor(short color); void setBottomBorderColor(short color);
void setBottomBorderColor(Color color); void setBottomBorderColor(Color color);

View File

@ -19,13 +19,13 @@ package org.apache.poi.ss.usermodel;
/** /**
* The enumeration value indicating the line style of a border in a cell, * The enumeration value indicating the line style of a border in a cell,
* i.e., whether it is borded dash dot, dash dot dot, dashed, dotted, double, hair, medium, * i.e., whether it is bordered dash dot, dash dot dot, dashed, dotted, double, hair, medium,
* medium dash dot, medium dash dot dot, medium dashed, none, slant dash dot, thick or thin. * medium dash dot, medium dash dot dot, medium dashed, none, slant dash dot, thick or thin.
*/ */
public enum BorderStyle { public enum BorderStyle {
/** /**
* No border * No border (default)
*/ */
NONE(0x0), NONE(0x0),
@ -86,24 +86,32 @@ package org.apache.poi.ss.usermodel;
/** /**
* medium dash-dot-dot border * medium dash-dot-dot border
* @deprecated POI 3.15 beta 1. Use {@link MEDIUM_DASH_DOT_DOT} instead.
*/ */
MEDIUM_DASH_DOT_DOTC(0xC),
MEDIUM_DASH_DOT_DOT(0xC), MEDIUM_DASH_DOT_DOT(0xC),
/** /**
* slanted dash-dot border * slanted dash-dot border
*/ */
SLANTED_DASH_DOT(0xD); SLANTED_DASH_DOT(0xD);
private final short code; private final short code;
BorderStyle(int code) { private BorderStyle(int code) {
this.code = (short)code; this.code = (short)code;
} }
public short getCode() { public short getCode() {
return code; return code;
} }
private static final BorderStyle[] _table = new BorderStyle[0xD + 1];
static {
for (BorderStyle c : values()) {
_table[c.getCode()] = c;
}
}
public static BorderStyle valueOf(short code) {
return _table[code];
}
} }

View File

@ -87,84 +87,98 @@ public interface CellStyle {
/** /**
* No border * No border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_NONE = 0x0; short BORDER_NONE = 0x0;
/** /**
* Thin border * Thin border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_THIN = 0x1; short BORDER_THIN = 0x1;
/** /**
* Medium border * Medium border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_MEDIUM = 0x2; short BORDER_MEDIUM = 0x2;
/** /**
* dash border * dash border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_DASHED = 0x3; short BORDER_DASHED = 0x3;
/** /**
* dot border * dot border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_DOTTED = 0x4; short BORDER_DOTTED = 0x4;
/** /**
* Thick border * Thick border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_THICK = 0x5; short BORDER_THICK = 0x5;
/** /**
* double-line border * double-line border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_DOUBLE = 0x6; short BORDER_DOUBLE = 0x6;
/** /**
* hair-line border * hair-line border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_HAIR = 0x7; short BORDER_HAIR = 0x7;
/** /**
* Medium dashed border * Medium dashed border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_MEDIUM_DASHED = 0x8; short BORDER_MEDIUM_DASHED = 0x8;
/** /**
* dash-dot border * dash-dot border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_DASH_DOT = 0x9; short BORDER_DASH_DOT = 0x9;
/** /**
* medium dash-dot border * medium dash-dot border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_MEDIUM_DASH_DOT = 0xA; short BORDER_MEDIUM_DASH_DOT = 0xA;
/** /**
* dash-dot-dot border * dash-dot-dot border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_DASH_DOT_DOT = 0xB; short BORDER_DASH_DOT_DOT = 0xB;
/** /**
* medium dash-dot-dot border * medium dash-dot-dot border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_MEDIUM_DASH_DOT_DOT = 0xC; short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
/** /**
* slanted dash-dot border * slanted dash-dot border
* @deprecated Use {@link BorderStyle}
*/ */
short BORDER_SLANTED_DASH_DOT = 0xD; short BORDER_SLANTED_DASH_DOT = 0xD;
@ -416,30 +430,21 @@ public interface CellStyle {
* @see #BORDER_DASH_DOT_DOT * @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT * @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
void setBorderLeft(short border); void setBorderLeft(short border);
/**
* set the type of border to use for the left border of the cell
* @param border type
*/
void setBorderLeft(BorderStyle border);
/** /**
* get the type of border to use for the left border of the cell * get the type of border to use for the left border of the cell
* @return border type * @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/ */
BorderStyle getBorderLeft();
short getBorderLeft();
/** /**
* set the type of border to use for the right border of the cell * set the type of border to use for the right border of the cell
@ -458,30 +463,21 @@ public interface CellStyle {
* @see #BORDER_DASH_DOT_DOT * @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT * @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
void setBorderRight(short border); void setBorderRight(short border);
/**
* set the type of border to use for the right border of the cell
* @param border type
*/
void setBorderRight(BorderStyle border);
/** /**
* get the type of border to use for the right border of the cell * get the type of border to use for the right border of the cell
* @return border type * @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/ */
BorderStyle getBorderRight();
short getBorderRight();
/** /**
* set the type of border to use for the top border of the cell * set the type of border to use for the top border of the cell
@ -500,30 +496,21 @@ public interface CellStyle {
* @see #BORDER_DASH_DOT_DOT * @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT * @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
void setBorderTop(short border); void setBorderTop(short border);
/**
* set the type of border to use for the top border of the cell
* @param border type
*/
void setBorderTop(BorderStyle border);
/** /**
* get the type of border to use for the top border of the cell * get the type of border to use for the top border of the cell
* @return border type * @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/ */
BorderStyle getBorderTop();
short getBorderTop();
/** /**
* set the type of border to use for the bottom border of the cell * set the type of border to use for the bottom border of the cell
@ -542,29 +529,21 @@ public interface CellStyle {
* @see #BORDER_DASH_DOT_DOT * @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT * @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
void setBorderBottom(short border); void setBorderBottom(short border);
/**
* set the type of border to use for the bottom border of the cell
* @param border type
*/
void setBorderBottom(BorderStyle border);
/** /**
* get the type of border to use for the bottom border of the cell * get the type of border to use for the bottom border of the cell
* @return border type * @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/ */
short getBorderBottom(); BorderStyle getBorderBottom();
/** /**
* set the color to use for the left border * set the color to use for the left border

View File

@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
@ -277,10 +278,10 @@ public final class CellUtil {
private static Map<String, Object> getFormatProperties(CellStyle style) { private static Map<String, Object> getFormatProperties(CellStyle style) {
Map<String, Object> properties = new HashMap<String, Object>(); Map<String, Object> properties = new HashMap<String, Object>();
putShort(properties, ALIGNMENT, style.getAlignment()); putShort(properties, ALIGNMENT, style.getAlignment());
putShort(properties, BORDER_BOTTOM, style.getBorderBottom()); putBorderStyle(properties, BORDER_BOTTOM, style.getBorderBottom());
putShort(properties, BORDER_LEFT, style.getBorderLeft()); putBorderStyle(properties, BORDER_LEFT, style.getBorderLeft());
putShort(properties, BORDER_RIGHT, style.getBorderRight()); putBorderStyle(properties, BORDER_RIGHT, style.getBorderRight());
putShort(properties, BORDER_TOP, style.getBorderTop()); putBorderStyle(properties, BORDER_TOP, style.getBorderTop());
putShort(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor()); putShort(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor());
putShort(properties, DATA_FORMAT, style.getDataFormat()); putShort(properties, DATA_FORMAT, style.getDataFormat());
putShort(properties, FILL_BACKGROUND_COLOR, style.getFillBackgroundColor()); putShort(properties, FILL_BACKGROUND_COLOR, style.getFillBackgroundColor());
@ -309,10 +310,10 @@ public final class CellUtil {
*/ */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) { private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
style.setAlignment(getShort(properties, ALIGNMENT)); style.setAlignment(getShort(properties, ALIGNMENT));
style.setBorderBottom(getShort(properties, BORDER_BOTTOM)); style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
style.setBorderLeft(getShort(properties, BORDER_LEFT)); style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
style.setBorderRight(getShort(properties, BORDER_RIGHT)); style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
style.setBorderTop(getShort(properties, BORDER_TOP)); style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR)); style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
style.setDataFormat(getShort(properties, DATA_FORMAT)); style.setDataFormat(getShort(properties, DATA_FORMAT));
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR)); style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
@ -345,6 +346,18 @@ public final class CellUtil {
} }
return 0; return 0;
} }
/**
* Utility method that returns the named BorderStyle value form the given map.
*
* @param properties map of named properties (String -> Object)
* @param name property name
* @return Border style if set, otherwise {@link BorderStyle#NONE}
*/
private static BorderStyle getBorderStyle(Map<String, Object> properties, String name) {
BorderStyle value = (BorderStyle) properties.get(name);
return (value != null) ? value : BorderStyle.NONE;
}
/** /**
* Utility method that returns the named boolean value form the given map. * Utility method that returns the named boolean value form the given map.
@ -373,6 +386,17 @@ public final class CellUtil {
private static void putShort(Map<String, Object> properties, String name, short value) { private static void putShort(Map<String, Object> properties, String name, short value) {
properties.put(name, Short.valueOf(value)); properties.put(name, Short.valueOf(value));
} }
/**
* Utility method that puts the named short value to the given map.
*
* @param properties map of properties (String -> Object)
* @param name property name
* @param value property value
*/
private static void putBorderStyle(Map<String, Object> properties, String name, BorderStyle border) {
properties.put(name, border);
}
/** /**
* Utility method that puts the named boolean value to the given map. * Utility method that puts the named boolean value to the given map.

View File

@ -17,6 +17,7 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.BorderFormatting; import org.apache.poi.ss.usermodel.BorderFormatting;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Color; import org.apache.poi.ss.usermodel.Color;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
@ -34,126 +35,183 @@ public class XSSFBorderFormatting implements BorderFormatting {
_border = border; _border = border;
} }
public short getBorderBottom() { @Override
public BorderStyle getBorderBottom() {
STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
} }
public short getBorderDiagonal() { @Override
public BorderStyle getBorderDiagonal() {
STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
} }
public short getBorderLeft() { @Override
public BorderStyle getBorderLeft() {
STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
} }
public short getBorderRight() { @Override
public BorderStyle getBorderRight() {
STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
} }
public short getBorderTop() { @Override
public BorderStyle getBorderTop() {
STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
} }
@Override
public XSSFColor getBottomBorderColorColor() { public XSSFColor getBottomBorderColorColor() {
if(!_border.isSetBottom()) return null; if(!_border.isSetBottom()) return null;
CTBorderPr pr = _border.getBottom(); CTBorderPr pr = _border.getBottom();
return new XSSFColor(pr.getColor()); return new XSSFColor(pr.getColor());
} }
@Override
public short getBottomBorderColor() { public short getBottomBorderColor() {
XSSFColor color = getBottomBorderColorColor(); XSSFColor color = getBottomBorderColorColor();
if (color == null) return 0; if (color == null) return 0;
return color.getIndexed(); return color.getIndexed();
} }
@Override
public XSSFColor getDiagonalBorderColorColor() { public XSSFColor getDiagonalBorderColorColor() {
if(!_border.isSetDiagonal()) return null; if(!_border.isSetDiagonal()) return null;
CTBorderPr pr = _border.getDiagonal(); CTBorderPr pr = _border.getDiagonal();
return new XSSFColor(pr.getColor()); return new XSSFColor(pr.getColor());
} }
@Override
public short getDiagonalBorderColor() { public short getDiagonalBorderColor() {
XSSFColor color = getDiagonalBorderColorColor(); XSSFColor color = getDiagonalBorderColorColor();
if (color == null) return 0; if (color == null) return 0;
return color.getIndexed(); return color.getIndexed();
} }
@Override
public XSSFColor getLeftBorderColorColor() { public XSSFColor getLeftBorderColorColor() {
if(!_border.isSetLeft()) return null; if(!_border.isSetLeft()) return null;
CTBorderPr pr = _border.getLeft(); CTBorderPr pr = _border.getLeft();
return new XSSFColor(pr.getColor()); return new XSSFColor(pr.getColor());
} }
@Override
public short getLeftBorderColor() { public short getLeftBorderColor() {
XSSFColor color = getLeftBorderColorColor(); XSSFColor color = getLeftBorderColorColor();
if (color == null) return 0; if (color == null) return 0;
return color.getIndexed(); return color.getIndexed();
} }
@Override
public XSSFColor getRightBorderColorColor() { public XSSFColor getRightBorderColorColor() {
if(!_border.isSetRight()) return null; if(!_border.isSetRight()) return null;
CTBorderPr pr = _border.getRight(); CTBorderPr pr = _border.getRight();
return new XSSFColor(pr.getColor()); return new XSSFColor(pr.getColor());
} }
@Override
public short getRightBorderColor() { public short getRightBorderColor() {
XSSFColor color = getRightBorderColorColor(); XSSFColor color = getRightBorderColorColor();
if (color == null) return 0; if (color == null) return 0;
return color.getIndexed(); return color.getIndexed();
} }
@Override
public XSSFColor getTopBorderColorColor() { public XSSFColor getTopBorderColorColor() {
if(!_border.isSetTop()) return null; if(!_border.isSetTop()) return null;
CTBorderPr pr = _border.getTop(); CTBorderPr pr = _border.getTop();
return new XSSFColor(pr.getColor()); return new XSSFColor(pr.getColor());
} }
@Override
public short getTopBorderColor() { public short getTopBorderColor() {
XSSFColor color = getRightBorderColorColor(); XSSFColor color = getRightBorderColorColor();
if (color == null) return 0; if (color == null) return 0;
return color.getIndexed(); return color.getIndexed();
} }
/**
* @deprecated 3.15 beta 1. Use {@link #setBorderBottom(BorderStyle)}
*/
@Override
public void setBorderBottom(short border) { public void setBorderBottom(short border) {
setBorderBottom(BorderStyle.valueOf(border));
}
@Override
public void setBorderBottom(BorderStyle border) {
CTBorderPr pr = _border.isSetBottom() ? _border.getBottom() : _border.addNewBottom(); CTBorderPr pr = _border.isSetBottom() ? _border.getBottom() : _border.addNewBottom();
if(border == BORDER_NONE) _border.unsetBottom(); if(border == BorderStyle.NONE) _border.unsetBottom();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
} }
/**
* @deprecated 3.15 beta 1. Use {@link #setBorderDiagonal(BorderStyle)}
*/
@Override
public void setBorderDiagonal(short border) { public void setBorderDiagonal(short border) {
setBorderDiagonal(BorderStyle.valueOf(border));
}
@Override
public void setBorderDiagonal(BorderStyle border) {
CTBorderPr pr = _border.isSetDiagonal() ? _border.getDiagonal() : _border.addNewDiagonal(); CTBorderPr pr = _border.isSetDiagonal() ? _border.getDiagonal() : _border.addNewDiagonal();
if(border == BORDER_NONE) _border.unsetDiagonal(); if(border == BorderStyle.NONE) _border.unsetDiagonal();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
} }
/**
* @deprecated 3.15 beta 1. Use {@link #setBorderLeft(BorderStyle)}
*/
@Override
public void setBorderLeft(short border) { public void setBorderLeft(short border) {
setBorderLeft(BorderStyle.valueOf(border));
}
@Override
public void setBorderLeft(BorderStyle border) {
CTBorderPr pr = _border.isSetLeft() ? _border.getLeft() : _border.addNewLeft(); CTBorderPr pr = _border.isSetLeft() ? _border.getLeft() : _border.addNewLeft();
if(border == BORDER_NONE) _border.unsetLeft(); if(border == BorderStyle.NONE) _border.unsetLeft();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
} }
/**
* @deprecated 3.15 beta 1. Use {@link #setBorderRight(BorderStyle)}
*/
@Override
public void setBorderRight(short border) { public void setBorderRight(short border) {
setBorderRight(BorderStyle.valueOf(border));
}
@Override
public void setBorderRight(BorderStyle border) {
CTBorderPr pr = _border.isSetRight() ? _border.getRight() : _border.addNewRight(); CTBorderPr pr = _border.isSetRight() ? _border.getRight() : _border.addNewRight();
if(border == BORDER_NONE) _border.unsetRight(); if(border == BorderStyle.NONE) _border.unsetRight();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
} }
/**
* @deprecated 3.15 beta 1. Use {@link #setBorderTop(BorderStyle)}
*/
@Override
public void setBorderTop(short border) { public void setBorderTop(short border) {
setBorderTop(BorderStyle.valueOf(border));
}
@Override
public void setBorderTop(BorderStyle border) {
CTBorderPr pr = _border.isSetTop() ? _border.getTop() : _border.addNewTop(); CTBorderPr pr = _border.isSetTop() ? _border.getTop() : _border.addNewTop();
if(border == BORDER_NONE) _border.unsetTop(); if(border == BorderStyle.NONE) _border.unsetTop();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
} }
@Override
public void setBottomBorderColor(Color color) { public void setBottomBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color); XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setBottomBorderColor((CTColor)null); if (xcolor == null) setBottomBorderColor((CTColor)null);
else setBottomBorderColor(xcolor.getCTColor()); else setBottomBorderColor(xcolor.getCTColor());
} }
@Override
public void setBottomBorderColor(short color) { public void setBottomBorderColor(short color) {
CTColor ctColor = CTColor.Factory.newInstance(); CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color); ctColor.setIndexed(color);
@ -168,11 +226,13 @@ public class XSSFBorderFormatting implements BorderFormatting {
} }
} }
@Override
public void setDiagonalBorderColor(Color color) { public void setDiagonalBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color); XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setDiagonalBorderColor((CTColor)null); if (xcolor == null) setDiagonalBorderColor((CTColor)null);
else setDiagonalBorderColor(xcolor.getCTColor()); else setDiagonalBorderColor(xcolor.getCTColor());
} }
@Override
public void setDiagonalBorderColor(short color) { public void setDiagonalBorderColor(short color) {
CTColor ctColor = CTColor.Factory.newInstance(); CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color); ctColor.setIndexed(color);
@ -187,11 +247,13 @@ public class XSSFBorderFormatting implements BorderFormatting {
} }
} }
@Override
public void setLeftBorderColor(Color color) { public void setLeftBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color); XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setLeftBorderColor((CTColor)null); if (xcolor == null) setLeftBorderColor((CTColor)null);
else setLeftBorderColor(xcolor.getCTColor()); else setLeftBorderColor(xcolor.getCTColor());
} }
@Override
public void setLeftBorderColor(short color) { public void setLeftBorderColor(short color) {
CTColor ctColor = CTColor.Factory.newInstance(); CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color); ctColor.setIndexed(color);
@ -206,11 +268,13 @@ public class XSSFBorderFormatting implements BorderFormatting {
} }
} }
@Override
public void setRightBorderColor(Color color) { public void setRightBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color); XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setRightBorderColor((CTColor)null); if (xcolor == null) setRightBorderColor((CTColor)null);
else setRightBorderColor(xcolor.getCTColor()); else setRightBorderColor(xcolor.getCTColor());
} }
@Override
public void setRightBorderColor(short color) { public void setRightBorderColor(short color) {
CTColor ctColor = CTColor.Factory.newInstance(); CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color); ctColor.setIndexed(color);
@ -225,11 +289,13 @@ public class XSSFBorderFormatting implements BorderFormatting {
} }
} }
@Override
public void setTopBorderColor(Color color) { public void setTopBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color); XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setTopBorderColor((CTColor)null); if (xcolor == null) setTopBorderColor((CTColor)null);
else setTopBorderColor(xcolor.getCTColor()); else setTopBorderColor(xcolor.getCTColor());
} }
@Override
public void setTopBorderColor(short color) { public void setTopBorderColor(short color) {
CTColor ctColor = CTColor.Factory.newInstance(); CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color); ctColor.setIndexed(color);

View File

@ -251,109 +251,57 @@ public class XSSFCellStyle implements CellStyle {
/** /**
* Get the type of border to use for the bottom border of the cell * Get the type of border to use for the bottom border of the cell
* *
* @return short - border type * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THIN
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOTTED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THICK
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOUBLE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_HAIR
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
@Override @Override
public short getBorderBottom() { public BorderStyle getBorderBottom() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE; if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId(); int idx = (int)_cellXf.getBorderId();
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder(); CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetBottom() ? ct.getBottom().getStyle() : null; STBorderStyle.Enum ptrn = ct.isSetBottom() ? ct.getBottom().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); if (ptrn == null) {
return BorderStyle.NONE;
}
return BorderStyle.valueOf((short)(ptrn.intValue() - 1));
} }
/** /**
* Get the type of border to use for the bottom border of the cell * Get the type of border to use for the bottom border of the cell
* *
* @return border type as Java enum * @return border type as Java enum
* @see BorderStyle * @deprecated 3.15 beta 1. Use {@link #getBorderBottom}
*/ */
public BorderStyle getBorderBottomEnum() { public BorderStyle getBorderBottomEnum() {
int style = getBorderBottom(); return getBorderBottom();
return BorderStyle.values()[style];
} }
/** /**
* Get the type of border to use for the left border of the cell * Get the type of border to use for the left border of the cell
* *
* @return short - border type, default value is {@link org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE} * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THIN
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOTTED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THICK
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOUBLE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_HAIR
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
@Override @Override
public short getBorderLeft() { public BorderStyle getBorderLeft() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE; if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId(); int idx = (int)_cellXf.getBorderId();
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder(); CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetLeft() ? ct.getLeft().getStyle() : null; STBorderStyle.Enum ptrn = ct.isSetLeft() ? ct.getLeft().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); if (ptrn == null) {
return BorderStyle.NONE;
}
return BorderStyle.valueOf((short)(ptrn.intValue() - 1));
} }
/** /**
* Get the type of border to use for the left border of the cell * Get the type of border to use for the left border of the cell
* *
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @deprecated 3.15 beta 1. Use {@link #getBorderLeft}
*/ */
public BorderStyle getBorderLeftEnum() { public BorderStyle getBorderLeftEnum() {
int style = getBorderLeft(); return getBorderLeft();
return BorderStyle.values()[style];
}
/**
* Get the type of border to use for the right border of the cell
*
* @return short - border type, default value is {@link org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE}
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THIN
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOTTED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THICK
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOUBLE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_HAIR
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/
@Override
public short getBorderRight() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE;
int idx = (int)_cellXf.getBorderId();
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetRight() ? ct.getRight().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
} }
/** /**
@ -361,48 +309,55 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
*/ */
@Override
public BorderStyle getBorderRight() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetRight() ? ct.getRight().getStyle() : null;
if (ptrn == null) {
return BorderStyle.NONE;
}
return BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
/**
* Get the type of border to use for the right border of the cell
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @deprecated 3.15 beta 1. Use {@link #getBorderRight}
*/
public BorderStyle getBorderRightEnum() { public BorderStyle getBorderRightEnum() {
int style = getBorderRight(); return getBorderRight();
return BorderStyle.values()[style];
} }
/** /**
* Get the type of border to use for the top border of the cell * Get the type of border to use for the top border of the cell
* *
* @return short - border type, default value is {@link org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE} * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THIN
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOTTED
* @see org.apache.poi.ss.usermodel.CellStyle #BORDER_THICK
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOUBLE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_HAIR
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
@Override @Override
public short getBorderTop() { public BorderStyle getBorderTop() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE; if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId(); int idx = (int)_cellXf.getBorderId();
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder(); CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetTop() ? ct.getTop().getStyle() : null; STBorderStyle.Enum ptrn = ct.isSetTop() ? ct.getTop().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); if (ptrn == null) {
return BorderStyle.NONE;
}
return BorderStyle.valueOf((short) (ptrn.intValue() - 1));
} }
/** /**
* Get the type of border to use for the top border of the cell * Get the type of border to use for the top border of the cell
* *
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE} * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @deprecated 3.15 beta 1. Use {@link #getBorderTop}
*/ */
public BorderStyle getBorderTopEnum() { public BorderStyle getBorderTopEnum() {
int style = getBorderTop(); return getBorderTop();
return BorderStyle.values()[style];
} }
/** /**
@ -849,6 +804,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderBottom(short border) { public void setBorderBottom(short border) {
@ -869,8 +825,9 @@ public class XSSFCellStyle implements CellStyle {
* @param border - type of border to use * @param border - type of border to use
* @see org.apache.poi.ss.usermodel.BorderStyle * @see org.apache.poi.ss.usermodel.BorderStyle
*/ */
@Override
public void setBorderBottom(BorderStyle border) { public void setBorderBottom(BorderStyle border) {
setBorderBottom((short)border.ordinal()); setBorderBottom(border.getCode());
} }
/** /**
@ -890,6 +847,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderLeft(short border) { public void setBorderLeft(short border) {
@ -909,8 +867,9 @@ public class XSSFCellStyle implements CellStyle {
* *
* @param border the type of border to use * @param border the type of border to use
*/ */
@Override
public void setBorderLeft(BorderStyle border) { public void setBorderLeft(BorderStyle border) {
setBorderLeft((short)border.ordinal()); setBorderLeft(border.getCode());
} }
/** /**
@ -931,6 +890,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderRight(short border) { public void setBorderRight(short border) {
@ -950,8 +910,9 @@ public class XSSFCellStyle implements CellStyle {
* *
* @param border the type of border to use * @param border the type of border to use
*/ */
@Override
public void setBorderRight(BorderStyle border) { public void setBorderRight(BorderStyle border) {
setBorderRight((short)border.ordinal()); setBorderRight(border.getCode());
} }
/** /**
@ -972,9 +933,10 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderTop(short border) { public void setBorderTop(short border) {
CTBorder ct = getCTBorder(); CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop(); CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop();
if(border == BORDER_NONE) ct.unsetTop(); if(border == BORDER_NONE) ct.unsetTop();
@ -991,8 +953,9 @@ public void setBorderTop(short border) {
* *
* @param border the type of border to use * @param border the type of border to use
*/ */
@Override
public void setBorderTop(BorderStyle border) { public void setBorderTop(BorderStyle border) {
setBorderTop((short)border.ordinal()); setBorderTop(border.getCode());
} }
/** /**

View File

@ -0,0 +1,30 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import org.apache.poi.xssf.XSSFITestDataProvider;
/**
* @author Yegor Kozlov
*/
public final class TestXSSFBorderStyle extends BaseTestBorderStyle {
public TestXSSFBorderStyle() {
super(XSSFITestDataProvider.instance);
}
}

View File

@ -104,11 +104,11 @@ public class TestXSSFCellStyle {
@Test @Test
public void testGetSetBorderBottom() { public void testGetSetBorderBottom() {
//default values //default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderBottom()); assertEquals(BorderStyle.NONE, cellStyle.getBorderBottom());
int num = stylesTable.getBorders().size(); int num = stylesTable.getBorders().size();
cellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); cellStyle.setBorderBottom(BorderStyle.MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderBottom()); assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom());
//a new border has been added //a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size()); assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border //id of the created border
@ -121,15 +121,15 @@ public class TestXSSFCellStyle {
num = stylesTable.getBorders().size(); num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId //setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
cellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); cellStyle.setBorderBottom(BorderStyle.MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderBottom()); assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom());
} }
assertEquals(borderId, cellStyle.getCoreXf().getBorderId()); assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size()); assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder()); assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <bottom> element //setting border to none removes the <bottom> element
cellStyle.setBorderBottom(CellStyle.BORDER_NONE); cellStyle.setBorderBottom(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size()); assertEquals(num, stylesTable.getBorders().size());
borderId = (int)cellStyle.getCoreXf().getBorderId(); borderId = (int)cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
@ -139,11 +139,11 @@ public class TestXSSFCellStyle {
@Test @Test
public void testGetSetBorderRight() { public void testGetSetBorderRight() {
//default values //default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderRight()); assertEquals(BorderStyle.NONE, cellStyle.getBorderRight());
int num = stylesTable.getBorders().size(); int num = stylesTable.getBorders().size();
cellStyle.setBorderRight(CellStyle.BORDER_MEDIUM); cellStyle.setBorderRight(BorderStyle.MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderRight()); assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight());
//a new border has been added //a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size()); assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border //id of the created border
@ -156,15 +156,15 @@ public class TestXSSFCellStyle {
num = stylesTable.getBorders().size(); num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId //setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
cellStyle.setBorderRight(CellStyle.BORDER_MEDIUM); cellStyle.setBorderRight(BorderStyle.MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderRight()); assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight());
} }
assertEquals(borderId, cellStyle.getCoreXf().getBorderId()); assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size()); assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder()); assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <right> element //setting border to none removes the <right> element
cellStyle.setBorderRight(CellStyle.BORDER_NONE); cellStyle.setBorderRight(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size()); assertEquals(num, stylesTable.getBorders().size());
borderId = (int)cellStyle.getCoreXf().getBorderId(); borderId = (int)cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
@ -174,11 +174,11 @@ public class TestXSSFCellStyle {
@Test @Test
public void testGetSetBorderLeft() { public void testGetSetBorderLeft() {
//default values //default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderLeft()); assertEquals(BorderStyle.NONE, cellStyle.getBorderLeft());
int num = stylesTable.getBorders().size(); int num = stylesTable.getBorders().size();
cellStyle.setBorderLeft(CellStyle.BORDER_MEDIUM); cellStyle.setBorderLeft(BorderStyle.MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderLeft()); assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft());
//a new border has been added //a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size()); assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border //id of the created border
@ -191,15 +191,15 @@ public class TestXSSFCellStyle {
num = stylesTable.getBorders().size(); num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId //setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
cellStyle.setBorderLeft(CellStyle.BORDER_MEDIUM); cellStyle.setBorderLeft(BorderStyle.MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderLeft()); assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft());
} }
assertEquals(borderId, cellStyle.getCoreXf().getBorderId()); assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size()); assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder()); assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <left> element //setting border to none removes the <left> element
cellStyle.setBorderLeft(CellStyle.BORDER_NONE); cellStyle.setBorderLeft(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size()); assertEquals(num, stylesTable.getBorders().size());
borderId = (int)cellStyle.getCoreXf().getBorderId(); borderId = (int)cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
@ -209,11 +209,11 @@ public class TestXSSFCellStyle {
@Test @Test
public void testGetSetBorderTop() { public void testGetSetBorderTop() {
//default values //default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderTop()); assertEquals(BorderStyle.NONE, cellStyle.getBorderTop());
int num = stylesTable.getBorders().size(); int num = stylesTable.getBorders().size();
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM); cellStyle.setBorderTop(BorderStyle.MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop()); assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop());
//a new border has been added //a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size()); assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border //id of the created border
@ -226,165 +226,112 @@ public class TestXSSFCellStyle {
num = stylesTable.getBorders().size(); num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId //setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM); cellStyle.setBorderTop(BorderStyle.MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop()); assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop());
} }
assertEquals(borderId, cellStyle.getCoreXf().getBorderId()); assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size()); assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder()); assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <top> element //setting border to none removes the <top> element
cellStyle.setBorderTop(CellStyle.BORDER_NONE); cellStyle.setBorderTop(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size()); assertEquals(num, stylesTable.getBorders().size());
borderId = (int)cellStyle.getCoreXf().getBorderId(); borderId = (int)cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertFalse(ctBorder.isSetTop()); assertFalse(ctBorder.isSetTop());
} }
private void testGetSetBorderXMLBean(BorderStyle border, STBorderStyle.Enum expected) {
cellStyle.setBorderTop(border);
assertEquals(border, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(expected, ctBorder.getTop().getStyle());
}
// Border Styles, in BorderStyle/STBorderStyle enum order
@Test
public void testGetSetBorderNone() {
cellStyle.setBorderTop(BorderStyle.NONE);
assertEquals(BorderStyle.NONE, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertNull(ctBorder.getTop());
// no border style and STBorderStyle.NONE are equivalent
// POI prefers to unset the border style than explicitly set it STBorderStyle.NONE
}
@Test @Test
public void testGetSetBorderThin() { public void testGetSetBorderThin() {
cellStyle.setBorderTop(CellStyle.BORDER_THIN); testGetSetBorderXMLBean(BorderStyle.THIN, STBorderStyle.THIN);
assertEquals(CellStyle.BORDER_THIN, cellStyle.getBorderTop()); }
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0); @Test
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.THIN, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderMedium() { public void testGetSetBorderMedium() {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM); testGetSetBorderXMLBean(BorderStyle.MEDIUM, STBorderStyle.MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop()); }
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0); @Test
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderThick() {
cellStyle.setBorderTop(CellStyle.BORDER_THICK);
assertEquals(CellStyle.BORDER_THICK, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.THICK, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderHair() {
cellStyle.setBorderTop(CellStyle.BORDER_HAIR);
assertEquals(CellStyle.BORDER_HAIR, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.HAIR, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderDotted() {
cellStyle.setBorderTop(CellStyle.BORDER_DOTTED);
assertEquals(CellStyle.BORDER_DOTTED, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.DOTTED, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderDashed() { public void testGetSetBorderDashed() {
cellStyle.setBorderTop(CellStyle.BORDER_DASHED); testGetSetBorderXMLBean(BorderStyle.DASHED, STBorderStyle.DASHED);
assertEquals(CellStyle.BORDER_DASHED, cellStyle.getBorderTop()); }
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0); @Test
//check changes in the underlying xml bean public void testGetSetBorderDotted() {
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); testGetSetBorderXMLBean(BorderStyle.DOTTED, STBorderStyle.DOTTED);
assertEquals(STBorderStyle.DASHED, ctBorder.getTop().getStyle()); }
}
@Test
@Test public void testGetSetBorderThick() {
public void testGetSetBorderDashDot() { testGetSetBorderXMLBean(BorderStyle.THICK, STBorderStyle.THICK);
cellStyle.setBorderTop(CellStyle.BORDER_DASH_DOT); }
assertEquals(CellStyle.BORDER_DASH_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); @Test
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.DASH_DOT, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderDashDotDot() {
cellStyle.setBorderTop(CellStyle.BORDER_DASH_DOT_DOT);
assertEquals(CellStyle.BORDER_DASH_DOT_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.DASH_DOT_DOT, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderMediumDashDot() {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASH_DOT);
assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM_DASH_DOT, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderMediumDashDotDot() {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT);
assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM_DASH_DOT_DOT, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderMediumDashed() {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED);
assertEquals(CellStyle.BORDER_MEDIUM_DASHED, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM_DASHED, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderSlantDashDot() {
cellStyle.setBorderTop(CellStyle.BORDER_SLANTED_DASH_DOT);
assertEquals(CellStyle.BORDER_SLANTED_DASH_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.SLANT_DASH_DOT, ctBorder.getTop().getStyle());
}
@Test
public void testGetSetBorderDouble() { public void testGetSetBorderDouble() {
cellStyle.setBorderTop(CellStyle.BORDER_DOUBLE); testGetSetBorderXMLBean(BorderStyle.DOUBLE, STBorderStyle.DOUBLE);
assertEquals(CellStyle.BORDER_DOUBLE, cellStyle.getBorderTop()); }
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0); @Test
//check changes in the underlying xml bean public void testGetSetBorderHair() {
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder(); testGetSetBorderXMLBean(BorderStyle.HAIR, STBorderStyle.HAIR);
assertEquals(STBorderStyle.DOUBLE, ctBorder.getTop().getStyle()); }
}
@Test
@Test public void testGetSetBorderMediumDashed() {
testGetSetBorderXMLBean(BorderStyle.MEDIUM_DASHED, STBorderStyle.MEDIUM_DASHED);
}
@Test
public void testGetSetBorderDashDot() {
testGetSetBorderXMLBean(BorderStyle.DASH_DOT, STBorderStyle.DASH_DOT);
}
@Test
public void testGetSetBorderMediumDashDot() {
testGetSetBorderXMLBean(BorderStyle.MEDIUM_DASH_DOT, STBorderStyle.MEDIUM_DASH_DOT);
}
@Test
public void testGetSetBorderDashDotDot() {
testGetSetBorderXMLBean(BorderStyle.DASH_DOT_DOT, STBorderStyle.DASH_DOT_DOT);
}
@Test
public void testGetSetBorderMediumDashDotDot() {
testGetSetBorderXMLBean(BorderStyle.MEDIUM_DASH_DOT_DOT, STBorderStyle.MEDIUM_DASH_DOT_DOT);
}
@Test
public void testGetSetBorderSlantDashDot() {
testGetSetBorderXMLBean(BorderStyle.SLANTED_DASH_DOT, STBorderStyle.SLANT_DASH_DOT);
}
@Test
public void testGetSetBottomBorderColor() { public void testGetSetBottomBorderColor() {
//defaults //defaults
assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getBottomBorderColor()); assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getBottomBorderColor());
@ -780,21 +727,21 @@ public class TestXSSFCellStyle {
assertEquals(2, wb.getNumberOfFonts()); assertEquals(2, wb.getNumberOfFonts());
XSSFCellStyle orig = wb.createCellStyle(); XSSFCellStyle orig = wb.createCellStyle();
orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT); orig.setAlignment(CellStyle.ALIGN_RIGHT);
orig.setFont(fnt); orig.setFont(fnt);
orig.setDataFormat((short)18); orig.setDataFormat((short)18);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment()); assertTrue(CellStyle.ALIGN_RIGHT == orig.getAlignment());
assertTrue(fnt == orig.getFont()); assertTrue(fnt == orig.getFont());
assertTrue(18 == orig.getDataFormat()); assertTrue(18 == orig.getDataFormat());
XSSFCellStyle clone = wb.createCellStyle(); XSSFCellStyle clone = wb.createCellStyle();
assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); assertFalse(CellStyle.ALIGN_RIGHT == clone.getAlignment());
assertFalse(fnt == clone.getFont()); assertFalse(fnt == clone.getFont());
assertFalse(18 == clone.getDataFormat()); assertFalse(18 == clone.getDataFormat());
clone.cloneStyleFrom(orig); clone.cloneStyleFrom(orig);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); assertTrue(CellStyle.ALIGN_RIGHT == clone.getAlignment());
assertTrue(fnt == clone.getFont()); assertTrue(fnt == clone.getFont());
assertTrue(18 == clone.getDataFormat()); assertTrue(18 == clone.getDataFormat());
assertEquals(2, wb.getNumberOfFonts()); assertEquals(2, wb.getNumberOfFonts());
@ -1104,5 +1051,7 @@ public class TestXSSFCellStyle {
cellStyle.setRightBorderColor(null); cellStyle.setRightBorderColor(null);
assertNull(cellStyle.getRightBorderXSSFColor()); assertNull(cellStyle.getRightBorderXSSFColor());
workbook.close();
} }
} }

View File

@ -25,6 +25,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hwpf.converter.AbstractWordUtils; import org.apache.poi.hwpf.converter.AbstractWordUtils;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
@ -66,28 +67,28 @@ public class AbstractExcelUtils
} }
} }
public static String getBorderStyle( short xlsBorder ) public static String getBorderStyle( BorderStyle xlsBorder )
{ {
final String borderStyle; final String borderStyle;
switch ( xlsBorder ) switch ( xlsBorder )
{ {
case HSSFCellStyle.BORDER_NONE: case NONE:
borderStyle = "none"; borderStyle = "none";
break; break;
case HSSFCellStyle.BORDER_DASH_DOT: case DASH_DOT:
case HSSFCellStyle.BORDER_DASH_DOT_DOT: case DASH_DOT_DOT:
case HSSFCellStyle.BORDER_DOTTED: case DOTTED:
case HSSFCellStyle.BORDER_HAIR: case HAIR:
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT: case MEDIUM_DASH_DOT:
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT: case MEDIUM_DASH_DOT_DOT:
case HSSFCellStyle.BORDER_SLANTED_DASH_DOT: case SLANTED_DASH_DOT:
borderStyle = "dotted"; borderStyle = "dotted";
break; break;
case HSSFCellStyle.BORDER_DASHED: case DASHED:
case HSSFCellStyle.BORDER_MEDIUM_DASHED: case MEDIUM_DASHED:
borderStyle = "dashed"; borderStyle = "dashed";
break; break;
case HSSFCellStyle.BORDER_DOUBLE: case DOUBLE:
borderStyle = "double"; borderStyle = "double";
break; break;
default: default:
@ -97,17 +98,17 @@ public class AbstractExcelUtils
return borderStyle; return borderStyle;
} }
public static String getBorderWidth( short xlsBorder ) public static String getBorderWidth( BorderStyle xlsBorder )
{ {
final String borderWidth; final String borderWidth;
switch ( xlsBorder ) switch ( xlsBorder )
{ {
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT: case MEDIUM_DASH_DOT:
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT: case MEDIUM_DASH_DOT_DOT:
case HSSFCellStyle.BORDER_MEDIUM_DASHED: case MEDIUM_DASHED:
borderWidth = "2pt"; borderWidth = "2pt";
break; break;
case HSSFCellStyle.BORDER_THICK: case THICK:
borderWidth = "thick"; borderWidth = "thick";
break; break;
default: default:

View File

@ -38,6 +38,7 @@ import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hwpf.converter.FoDocumentFacade; import org.apache.poi.hwpf.converter.FoDocumentFacade;
import org.apache.poi.hwpf.converter.FontReplacer.Triplet; import org.apache.poi.hwpf.converter.FontReplacer.Triplet;
import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
@ -192,10 +193,10 @@ public class ExcelToFoConverter extends AbstractExcelConverter
protected boolean isEmptyStyle( CellStyle cellStyle ) { protected boolean isEmptyStyle( CellStyle cellStyle ) {
return cellStyle == null || ( return cellStyle == null || (
cellStyle.getFillPattern() == 0 cellStyle.getFillPattern() == 0
&& cellStyle.getBorderTop() == HSSFCellStyle.BORDER_NONE && cellStyle.getBorderTop() == BorderStyle.NONE
&& cellStyle.getBorderRight() == HSSFCellStyle.BORDER_NONE && cellStyle.getBorderRight() == BorderStyle.NONE
&& cellStyle.getBorderBottom() == HSSFCellStyle.BORDER_NONE && cellStyle.getBorderBottom() == BorderStyle.NONE
&& cellStyle.getBorderLeft() == HSSFCellStyle.BORDER_NONE && cellStyle.getBorderLeft() == BorderStyle.NONE
); );
} }
@ -374,9 +375,9 @@ public class ExcelToFoConverter extends AbstractExcelConverter
} }
protected void processCellStyleBorder( HSSFWorkbook workbook, protected void processCellStyleBorder( HSSFWorkbook workbook,
Element cellTarget, String type, short xlsBorder, short borderColor ) Element cellTarget, String type, BorderStyle xlsBorder, short borderColor )
{ {
if ( xlsBorder == HSSFCellStyle.BORDER_NONE ) if ( xlsBorder == BorderStyle.NONE )
return; return;
StringBuilder borderStyle = new StringBuilder(); StringBuilder borderStyle = new StringBuilder();

View File

@ -42,6 +42,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hwpf.converter.HtmlDocumentFacade; import org.apache.poi.hwpf.converter.HtmlDocumentFacade;
import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
@ -190,9 +191,9 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
} }
private void buildStyle_border( HSSFWorkbook workbook, StringBuilder style, private void buildStyle_border( HSSFWorkbook workbook, StringBuilder style,
String type, short xlsBorder, short borderColor ) String type, BorderStyle xlsBorder, short borderColor )
{ {
if ( xlsBorder == HSSFCellStyle.BORDER_NONE ) { if ( xlsBorder == BorderStyle.NONE ) {
return; return;
} }

View File

@ -68,6 +68,7 @@ import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.DeletedArea3DPtg; import org.apache.poi.ss.formula.ptg.DeletedArea3DPtg;
import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
@ -2564,7 +2565,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFSheet sheet = wb.getSheetAt(0); HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(0); HSSFRow row = sheet.getRow(0);
HSSFCellStyle rstyle = row.getRowStyle(); HSSFCellStyle rstyle = row.getRowStyle();
assertEquals(rstyle.getBorderBottom(), CellStyle.BORDER_DOUBLE); assertEquals(BorderStyle.DOUBLE, rstyle.getBorderBottom());
wb.close(); wb.close();
} }

View File

@ -24,6 +24,7 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
@ -180,10 +181,10 @@ public final class TestCellStyle extends TestCase {
HSSFCellStyle cs = wb.createCellStyle(); HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle();
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs.setBorderBottom(BorderStyle.THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs.setBorderLeft(BorderStyle.THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN); cs.setBorderRight(BorderStyle.THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN); cs.setBorderTop(BorderStyle.THIN);
cs.setFillForegroundColor(( short ) 0xA); cs.setFillForegroundColor(( short ) 0xA);
cs.setFillPattern(( short ) 1); cs.setFillPattern(( short ) 1);
fnt.setColor(( short ) 0xf); fnt.setColor(( short ) 0xf);
@ -346,40 +347,40 @@ public final class TestCellStyle extends TestCase {
HSSFCellStyle cs; HSSFCellStyle cs;
cs = s.getRow(0).getCell(0).getCellStyle(); cs = s.getRow(0).getCell(0).getCellStyle();
assertEquals(CellStyle.BORDER_HAIR, cs.getBorderRight()); assertEquals(BorderStyle.HAIR, cs.getBorderRight());
cs = s.getRow(1).getCell(1).getCellStyle(); cs = s.getRow(1).getCell(1).getCellStyle();
assertEquals(CellStyle.BORDER_DOTTED, cs.getBorderRight()); assertEquals(BorderStyle.DOTTED, cs.getBorderRight());
cs = s.getRow(2).getCell(2).getCellStyle(); cs = s.getRow(2).getCell(2).getCellStyle();
assertEquals(CellStyle.BORDER_DASH_DOT_DOT, cs.getBorderRight()); assertEquals(BorderStyle.DASH_DOT_DOT, cs.getBorderRight());
cs = s.getRow(3).getCell(3).getCellStyle(); cs = s.getRow(3).getCell(3).getCellStyle();
assertEquals(CellStyle.BORDER_DASHED, cs.getBorderRight()); assertEquals(BorderStyle.DASHED, cs.getBorderRight());
cs = s.getRow(4).getCell(4).getCellStyle(); cs = s.getRow(4).getCell(4).getCellStyle();
assertEquals(CellStyle.BORDER_THIN, cs.getBorderRight()); assertEquals(BorderStyle.THIN, cs.getBorderRight());
cs = s.getRow(5).getCell(5).getCellStyle(); cs = s.getRow(5).getCell(5).getCellStyle();
assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT, cs.getBorderRight()); assertEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, cs.getBorderRight());
cs = s.getRow(6).getCell(6).getCellStyle(); cs = s.getRow(6).getCell(6).getCellStyle();
assertEquals(CellStyle.BORDER_SLANTED_DASH_DOT, cs.getBorderRight()); assertEquals(BorderStyle.SLANTED_DASH_DOT, cs.getBorderRight());
cs = s.getRow(7).getCell(7).getCellStyle(); cs = s.getRow(7).getCell(7).getCellStyle();
assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT, cs.getBorderRight()); assertEquals(BorderStyle.MEDIUM_DASH_DOT, cs.getBorderRight());
cs = s.getRow(8).getCell(8).getCellStyle(); cs = s.getRow(8).getCell(8).getCellStyle();
assertEquals(CellStyle.BORDER_MEDIUM_DASHED, cs.getBorderRight()); assertEquals(BorderStyle.MEDIUM_DASHED, cs.getBorderRight());
cs = s.getRow(9).getCell(9).getCellStyle(); cs = s.getRow(9).getCell(9).getCellStyle();
assertEquals(CellStyle.BORDER_MEDIUM, cs.getBorderRight()); assertEquals(BorderStyle.MEDIUM, cs.getBorderRight());
cs = s.getRow(10).getCell(10).getCellStyle(); cs = s.getRow(10).getCell(10).getCellStyle();
assertEquals(CellStyle.BORDER_THICK, cs.getBorderRight()); assertEquals(BorderStyle.THICK, cs.getBorderRight());
cs = s.getRow(11).getCell(11).getCellStyle(); cs = s.getRow(11).getCell(11).getCellStyle();
assertEquals(CellStyle.BORDER_DOUBLE, cs.getBorderRight()); assertEquals(BorderStyle.DOUBLE, cs.getBorderRight());
} }
public void testShrinkToFit() { public void testShrinkToFit() {
@ -485,7 +486,7 @@ public final class TestCellStyle extends TestCase {
font.setColor(Font.COLOR_RED); font.setColor(Font.COLOR_RED);
CellStyle style = wb.createCellStyle(); CellStyle style = wb.createCellStyle();
style.setBorderBottom(CellStyle.BORDER_DOTTED); style.setBorderBottom(BorderStyle.DOTTED);
style.setFont(font); style.setFont(font);
Cell cell = row.createCell(0); Cell cell = row.createCell(0);
@ -498,7 +499,7 @@ public final class TestCellStyle extends TestCase {
newCell.setCellValue("2testtext2"); newCell.setCellValue("2testtext2");
CellStyle newStyle = newCell.getCellStyle(); CellStyle newStyle = newCell.getCellStyle();
assertEquals(CellStyle.BORDER_DOTTED, newStyle.getBorderBottom()); assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottom());
assertEquals(Font.COLOR_RED, ((HSSFCellStyle)newStyle).getFont(wb).getColor()); assertEquals(Font.COLOR_RED, ((HSSFCellStyle)newStyle).getFont(wb).getColor());
// OutputStream out = new FileOutputStream("/tmp/56959.xls"); // OutputStream out = new FileOutputStream("/tmp/56959.xls");

View File

@ -16,6 +16,8 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import org.apache.poi.ss.usermodel.BorderStyle;
import junit.framework.TestCase; import junit.framework.TestCase;
public final class TestHSSFOptimiser extends TestCase { public final class TestHSSFOptimiser extends TestCase {
@ -278,13 +280,13 @@ public final class TestHSSFOptimiser extends TestCase {
assertEquals(21, wb.getNumCellStyles()); assertEquals(21, wb.getNumCellStyles());
HSSFCellStyle cs1 = wb.createCellStyle(); HSSFCellStyle cs1 = wb.createCellStyle();
cs1.setBorderBottom(HSSFCellStyle.BORDER_THICK); cs1.setBorderBottom(BorderStyle.THICK);
HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle();
cs2.setBorderBottom(HSSFCellStyle.BORDER_DASH_DOT); cs2.setBorderBottom(BorderStyle.DASH_DOT);
HSSFCellStyle cs3 = wb.createCellStyle(); // = cs1 HSSFCellStyle cs3 = wb.createCellStyle(); // = cs1
cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK); cs3.setBorderBottom(BorderStyle.THICK);
assertEquals(24, wb.getNumCellStyles()); assertEquals(24, wb.getNumCellStyles());
@ -306,8 +308,8 @@ public final class TestHSSFOptimiser extends TestCase {
// Check // Check
assertEquals(23, wb.getNumCellStyles()); assertEquals(23, wb.getNumCellStyles());
assertEquals(HSSFCellStyle.BORDER_THICK, r.getCell(0).getCellStyle().getBorderBottom()); assertEquals(BorderStyle.THICK, r.getCell(0).getCellStyle().getBorderBottom());
assertEquals(HSSFCellStyle.BORDER_DASH_DOT, r.getCell(1).getCellStyle().getBorderBottom()); assertEquals(BorderStyle.DASH_DOT, r.getCell(1).getCellStyle().getBorderBottom());
assertEquals(HSSFCellStyle.BORDER_THICK, r.getCell(2).getCellStyle().getBorderBottom()); assertEquals(BorderStyle.THICK, r.getCell(2).getCellStyle().getBorderBottom());
} }
} }

View File

@ -20,6 +20,7 @@ package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BorderStyle;
/** /**
* Class to test row styling functionality * Class to test row styling functionality
@ -110,10 +111,10 @@ public final class TestRowStyle extends TestCase {
HSSFCellStyle cs = wb.createCellStyle(); HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle();
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs.setBorderBottom(BorderStyle.THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs.setBorderLeft(BorderStyle.THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN); cs.setBorderRight(BorderStyle.THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN); cs.setBorderTop(BorderStyle.THIN);
cs.setFillForegroundColor(( short ) 0xA); cs.setFillForegroundColor(( short ) 0xA);
cs.setFillPattern(( short ) 1); cs.setFillPattern(( short ) 1);
fnt.setColor(( short ) 0xf); fnt.setColor(( short ) 0xf);
@ -150,12 +151,12 @@ public final class TestRowStyle extends TestCase {
assertNotNull("Row is not null", r); assertNotNull("Row is not null", r);
cs = r.getRowStyle(); cs = r.getRowStyle();
assertEquals("FillForegroundColor for row: ", cs.getBorderBottom(), HSSFCellStyle.BORDER_THIN); assertEquals("Bottom Border Style for row:", BorderStyle.THIN, cs.getBorderBottom());
assertEquals("FillPattern for row: ", cs.getBorderLeft(), HSSFCellStyle.BORDER_THIN); assertEquals("Left Border Style for row:", BorderStyle.THIN, cs.getBorderLeft());
assertEquals("FillForegroundColor for row: ", cs.getBorderRight(), HSSFCellStyle.BORDER_THIN); assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRight());
assertEquals("FillPattern for row: ", cs.getBorderTop(), HSSFCellStyle.BORDER_THIN); assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTop());
assertEquals("FillForegroundColor for row: ", cs.getFillForegroundColor(), 0xA); assertEquals("FillForegroundColor for row:", 0xA, cs.getFillForegroundColor());
assertEquals("FillPattern for row: ", cs.getFillPattern(), (short) 0x1); assertEquals("FillPattern for row:", 0x1, cs.getFillPattern());
rownum++; rownum++;
if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/ if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/

View File

@ -0,0 +1,82 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
2012 - Alfresco Software, Ltd.
Alfresco Software has modified source of this file
The details of changes as svn diff can be found in svn at location root/projects/3rd-party/src
==================================================================== */
package org.apache.poi.ss.usermodel;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.apache.poi.ss.ITestDataProvider;
import org.junit.Test;
/**
* Tests of {@link BorderStyle}
*/
public class BaseTestBorderStyle {
private final ITestDataProvider _testDataProvider;
protected BaseTestBorderStyle(ITestDataProvider testDataProvider) {
_testDataProvider = testDataProvider;
}
/**
* Test that we use the specified locale when deciding
* how to format normal numbers
*/
@Test
public void testBorderStyle() throws IOException {
String ext = _testDataProvider.getStandardFileNameExtension();
Workbook wb = _testDataProvider.openSampleWorkbook("59264."+ext);
Sheet sh = wb.getSheetAt(0);
assertBorderStyleEquals(BorderStyle.NONE, getDiagonalCell(sh, 0));
assertBorderStyleEquals(BorderStyle.THIN, getDiagonalCell(sh, 1));
assertBorderStyleEquals(BorderStyle.MEDIUM, getDiagonalCell(sh, 2));
assertBorderStyleEquals(BorderStyle.DASHED, getDiagonalCell(sh, 3));
assertBorderStyleEquals(BorderStyle.DOTTED, getDiagonalCell(sh, 4));
assertBorderStyleEquals(BorderStyle.THICK, getDiagonalCell(sh, 5));
assertBorderStyleEquals(BorderStyle.DOUBLE, getDiagonalCell(sh, 6));
assertBorderStyleEquals(BorderStyle.HAIR, getDiagonalCell(sh, 7));
assertBorderStyleEquals(BorderStyle.MEDIUM_DASHED, getDiagonalCell(sh, 8));
assertBorderStyleEquals(BorderStyle.DASH_DOT, getDiagonalCell(sh, 9));
assertBorderStyleEquals(BorderStyle.MEDIUM_DASH_DOT, getDiagonalCell(sh, 10));
assertBorderStyleEquals(BorderStyle.DASH_DOT_DOT, getDiagonalCell(sh, 11));
assertBorderStyleEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, getDiagonalCell(sh, 12));
assertBorderStyleEquals(BorderStyle.SLANTED_DASH_DOT, getDiagonalCell(sh, 13));
wb.close();
}
private Cell getDiagonalCell(Sheet sheet, int n) {
return sheet.getRow(n).getCell(n);
}
protected void assertBorderStyleEquals(BorderStyle expected, Cell cell) {
CellStyle style = cell.getCellStyle();
assertEquals(expected, style.getBorderTop());
assertEquals(expected, style.getBorderBottom());
assertEquals(expected, style.getBorderLeft());
assertEquals(expected, style.getBorderRight());
}
}

View File

@ -254,10 +254,10 @@ public abstract class BaseTestCell {
f.setFontName("Arial Unicode MS"); f.setFontName("Arial Unicode MS");
cs.setFillBackgroundColor((short)3); cs.setFillBackgroundColor((short)3);
cs.setFont(f); cs.setFont(f);
cs.setBorderTop((short)1); cs.setBorderTop(BorderStyle.THIN);
cs.setBorderRight((short)1); cs.setBorderRight(BorderStyle.THIN);
cs.setBorderLeft((short)1); cs.setBorderLeft(BorderStyle.THIN);
cs.setBorderBottom((short)1); cs.setBorderBottom(BorderStyle.THIN);
r = s.createRow(0); r = s.createRow(0);
c=r.createCell(0); c=r.createCell(0);
@ -270,15 +270,15 @@ public abstract class BaseTestCell {
r = s.getRow(0); r = s.getRow(0);
c = r.getCell(0); c = r.getCell(0);
assertTrue("Formula Cell at 0,0", (c.getCellType()==Cell.CELL_TYPE_FORMULA)); assertEquals("Formula Cell at 0,0", Cell.CELL_TYPE_FORMULA, c.getCellType());
cs = c.getCellStyle(); cs = c.getCellStyle();
assertNotNull("Formula Cell Style", cs); assertNotNull("Formula Cell Style", cs);
assertTrue("Font Index Matches", (cs.getFontIndex() == f.getIndex())); assertEquals("Font Index Matches", f.getIndex(), cs.getFontIndex());
assertTrue("Top Border", (cs.getBorderTop() == (short)1)); assertEquals("Top Border", BorderStyle.THIN, cs.getBorderTop());
assertTrue("Left Border", (cs.getBorderLeft() == (short)1)); assertEquals("Left Border", BorderStyle.THIN, cs.getBorderLeft());
assertTrue("Right Border", (cs.getBorderRight() == (short)1)); assertEquals("Right Border", BorderStyle.THIN, cs.getBorderRight());
assertTrue("Bottom Border", (cs.getBorderBottom() == (short)1)); assertEquals("Bottom Border", BorderStyle.THIN, cs.getBorderBottom());
wb2.close(); wb2.close();
} }

View File

@ -323,10 +323,10 @@ public abstract class BaseTestConditionalFormatting {
fontFmt.setFontStyle(true, false); fontFmt.setFontStyle(true, false);
BorderFormatting bordFmt = rule1.createBorderFormatting(); BorderFormatting bordFmt = rule1.createBorderFormatting();
bordFmt.setBorderBottom(BorderFormatting.BORDER_THIN); bordFmt.setBorderBottom(BorderStyle.THIN);
bordFmt.setBorderTop(BorderFormatting.BORDER_THICK); bordFmt.setBorderTop(BorderStyle.THICK);
bordFmt.setBorderLeft(BorderFormatting.BORDER_DASHED); bordFmt.setBorderLeft(BorderStyle.DASHED);
bordFmt.setBorderRight(BorderFormatting.BORDER_DOTTED); bordFmt.setBorderRight(BorderStyle.DOTTED);
PatternFormatting patternFmt = rule1.createPatternFormatting(); PatternFormatting patternFmt = rule1.createPatternFormatting();
patternFmt.setFillBackgroundColor(IndexedColors.YELLOW.index); patternFmt.setFillBackgroundColor(IndexedColors.YELLOW.index);
@ -376,10 +376,10 @@ public abstract class BaseTestConditionalFormatting {
BorderFormatting r1bf = rule1.getBorderFormatting(); BorderFormatting r1bf = rule1.getBorderFormatting();
assertNotNull(r1bf); assertNotNull(r1bf);
assertEquals(BorderFormatting.BORDER_THIN, r1bf.getBorderBottom()); assertEquals(BorderStyle.THIN, r1bf.getBorderBottom());
assertEquals(BorderFormatting.BORDER_THICK,r1bf.getBorderTop()); assertEquals(BorderStyle.THICK,r1bf.getBorderTop());
assertEquals(BorderFormatting.BORDER_DASHED,r1bf.getBorderLeft()); assertEquals(BorderStyle.DASHED,r1bf.getBorderLeft());
assertEquals(BorderFormatting.BORDER_DOTTED,r1bf.getBorderRight()); assertEquals(BorderStyle.DOTTED,r1bf.getBorderRight());
PatternFormatting r1pf = rule1.getPatternFormatting(); PatternFormatting r1pf = rule1.getPatternFormatting();
assertNotNull(r1pf); assertNotNull(r1pf);
@ -453,7 +453,7 @@ public abstract class BaseTestConditionalFormatting {
ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule( ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(
ComparisonOperator.BETWEEN, "SUM(A10:A15)", "1+SUM(B16:B30)"); ComparisonOperator.BETWEEN, "SUM(A10:A15)", "1+SUM(B16:B30)");
BorderFormatting borderFmt = rule2.createBorderFormatting(); BorderFormatting borderFmt = rule2.createBorderFormatting();
borderFmt.setBorderDiagonal((short) 2); borderFmt.setBorderDiagonal(BorderStyle.MEDIUM);
CellRangeAddress [] regions = { CellRangeAddress [] regions = {
new CellRangeAddress(2, 4, 0, 0), // A3:A5 new CellRangeAddress(2, 4, 0, 0), // A3:A5
@ -1019,6 +1019,38 @@ public abstract class BaseTestConditionalFormatting {
workbook.close(); workbook.close();
} }
@Test
public void testAllCreateBorderFormatting() throws IOException {
// Make sure it is possible to create a conditional formatting rule
// with every type of Border Style
Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet();
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "7");
BorderFormatting borderFmt = rule1.createBorderFormatting();
for (BorderStyle border : BorderStyle.values()) {
borderFmt.setBorderTop(border);
assertEquals(border, borderFmt.getBorderTop());
borderFmt.setBorderBottom(border);
assertEquals(border, borderFmt.getBorderBottom());
borderFmt.setBorderLeft(border);
assertEquals(border, borderFmt.getBorderLeft());
borderFmt.setBorderRight(border);
assertEquals(border, borderFmt.getBorderRight());
borderFmt.setBorderDiagonal(border);
assertEquals(border, borderFmt.getBorderDiagonal());
}
workbook.close();
}
@Test @Test
public void testCreateBorderFormatting() throws IOException { public void testCreateBorderFormatting() throws IOException {
@ -1030,37 +1062,37 @@ public abstract class BaseTestConditionalFormatting {
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "7"); ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "7");
BorderFormatting borderFmt = rule1.createBorderFormatting(); BorderFormatting borderFmt = rule1.createBorderFormatting();
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderBottom()); assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom());
borderFmt.setBorderBottom(BorderFormatting.BORDER_DOTTED); borderFmt.setBorderBottom(BorderStyle.DOTTED);
assertEquals(BorderFormatting.BORDER_DOTTED, borderFmt.getBorderBottom()); assertEquals(BorderStyle.DOTTED, borderFmt.getBorderBottom());
borderFmt.setBorderBottom(BorderFormatting.BORDER_NONE); borderFmt.setBorderBottom(BorderStyle.NONE);
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderBottom()); assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom());
borderFmt.setBorderBottom(BorderFormatting.BORDER_THICK); borderFmt.setBorderBottom(BorderStyle.THICK);
assertEquals(BorderFormatting.BORDER_THICK, borderFmt.getBorderBottom()); assertEquals(BorderStyle.THICK, borderFmt.getBorderBottom());
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderTop()); assertEquals(BorderStyle.NONE, borderFmt.getBorderTop());
borderFmt.setBorderTop(BorderFormatting.BORDER_DOTTED); borderFmt.setBorderTop(BorderStyle.DOTTED);
assertEquals(BorderFormatting.BORDER_DOTTED, borderFmt.getBorderTop()); assertEquals(BorderStyle.DOTTED, borderFmt.getBorderTop());
borderFmt.setBorderTop(BorderFormatting.BORDER_NONE); borderFmt.setBorderTop(BorderStyle.NONE);
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderTop()); assertEquals(BorderStyle.NONE, borderFmt.getBorderTop());
borderFmt.setBorderTop(BorderFormatting.BORDER_THICK); borderFmt.setBorderTop(BorderStyle.THICK);
assertEquals(BorderFormatting.BORDER_THICK, borderFmt.getBorderTop()); assertEquals(BorderStyle.THICK, borderFmt.getBorderTop());
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderLeft()); assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft());
borderFmt.setBorderLeft(BorderFormatting.BORDER_DOTTED); borderFmt.setBorderLeft(BorderStyle.DOTTED);
assertEquals(BorderFormatting.BORDER_DOTTED, borderFmt.getBorderLeft()); assertEquals(BorderStyle.DOTTED, borderFmt.getBorderLeft());
borderFmt.setBorderLeft(BorderFormatting.BORDER_NONE); borderFmt.setBorderLeft(BorderStyle.NONE);
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderLeft()); assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft());
borderFmt.setBorderLeft(BorderFormatting.BORDER_THIN); borderFmt.setBorderLeft(BorderStyle.THIN);
assertEquals(BorderFormatting.BORDER_THIN, borderFmt.getBorderLeft()); assertEquals(BorderStyle.THIN, borderFmt.getBorderLeft());
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderRight()); assertEquals(BorderStyle.NONE, borderFmt.getBorderRight());
borderFmt.setBorderRight(BorderFormatting.BORDER_DOTTED); borderFmt.setBorderRight(BorderStyle.DOTTED);
assertEquals(BorderFormatting.BORDER_DOTTED, borderFmt.getBorderRight()); assertEquals(BorderStyle.DOTTED, borderFmt.getBorderRight());
borderFmt.setBorderRight(BorderFormatting.BORDER_NONE); borderFmt.setBorderRight(BorderStyle.NONE);
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderRight()); assertEquals(BorderStyle.NONE, borderFmt.getBorderRight());
borderFmt.setBorderRight(BorderFormatting.BORDER_HAIR); borderFmt.setBorderRight(BorderStyle.HAIR);
assertEquals(BorderFormatting.BORDER_HAIR, borderFmt.getBorderRight()); assertEquals(BorderStyle.HAIR, borderFmt.getBorderRight());
ConditionalFormattingRule [] cfRules = { rule1 }; ConditionalFormattingRule [] cfRules = { rule1 };
@ -1076,10 +1108,10 @@ public abstract class BaseTestConditionalFormatting {
BorderFormatting r1fp = cf.getRule(0).getBorderFormatting(); BorderFormatting r1fp = cf.getRule(0).getBorderFormatting();
assertNotNull(r1fp); assertNotNull(r1fp);
assertEquals(BorderFormatting.BORDER_THICK, r1fp.getBorderBottom()); assertEquals(BorderStyle.THICK, r1fp.getBorderBottom());
assertEquals(BorderFormatting.BORDER_THICK, r1fp.getBorderTop()); assertEquals(BorderStyle.THICK, r1fp.getBorderTop());
assertEquals(BorderFormatting.BORDER_THIN, r1fp.getBorderLeft()); assertEquals(BorderStyle.THIN, r1fp.getBorderLeft());
assertEquals(BorderFormatting.BORDER_HAIR, r1fp.getBorderRight()); assertEquals(BorderStyle.HAIR, r1fp.getBorderRight());
workbook.close(); workbook.close();
} }

View File

@ -0,0 +1,30 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import org.apache.poi.hssf.HSSFITestDataProvider;
/**
* @author Yegor Kozlov
*/
public final class TestHSSFBorderStyle extends BaseTestBorderStyle {
public TestHSSFBorderStyle() {
super(HSSFITestDataProvider.instance);
}
}

View File

@ -29,13 +29,13 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test; import org.junit.Test;
/** /**
@ -53,13 +53,13 @@ public final class TestCellUtil {
// Add a border should create a new style // Add a border should create a new style
int styCnt1 = wb.getNumCellStyles(); int styCnt1 = wb.getNumCellStyles();
CellUtil.setCellStyleProperty(c, wb, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN); CellUtil.setCellStyleProperty(c, wb, CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
int styCnt2 = wb.getNumCellStyles(); int styCnt2 = wb.getNumCellStyles();
assertEquals(styCnt2, styCnt1+1); assertEquals(styCnt2, styCnt1+1);
// Add same border to another cell, should not create another style // Add same border to another cell, should not create another style
c = r.createCell(1); c = r.createCell(1);
CellUtil.setCellStyleProperty(c, wb, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN); CellUtil.setCellStyleProperty(c, wb, CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
int styCnt3 = wb.getNumCellStyles(); int styCnt3 = wb.getNumCellStyles();
assertEquals(styCnt3, styCnt2); assertEquals(styCnt3, styCnt2);
@ -76,19 +76,19 @@ public final class TestCellUtil {
// Add multiple border properties to cell should create a single new style // Add multiple border properties to cell should create a single new style
int styCnt1 = wb.getNumCellStyles(); int styCnt1 = wb.getNumCellStyles();
Map<String, Object> props = new HashMap<String, Object>(); Map<String, Object> props = new HashMap<String, Object>();
props.put(CellUtil.BORDER_TOP, CellStyle.BORDER_THIN); props.put(CellUtil.BORDER_TOP, BorderStyle.THIN);
props.put(CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN); props.put(CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
props.put(CellUtil.BORDER_LEFT, CellStyle.BORDER_THIN); props.put(CellUtil.BORDER_LEFT, BorderStyle.THIN);
props.put(CellUtil.BORDER_RIGHT, CellStyle.BORDER_THIN); props.put(CellUtil.BORDER_RIGHT, BorderStyle.THIN);
CellUtil.setCellStyleProperties(c, props); CellUtil.setCellStyleProperties(c, props);
int styCnt2 = wb.getNumCellStyles(); int styCnt2 = wb.getNumCellStyles();
assertEquals(styCnt2, styCnt1+1); assertEquals(styCnt1+1, styCnt2);
// Add same border another to same cell, should not create another style // Add same border another to same cell, should not create another style
c = r.createCell(1); c = r.createCell(1);
CellUtil.setCellStyleProperties(c, props); CellUtil.setCellStyleProperties(c, props);
int styCnt3 = wb.getNumCellStyles(); int styCnt3 = wb.getNumCellStyles();
assertEquals(styCnt3, styCnt2); assertEquals(styCnt2, styCnt3);
wb.close(); wb.close();
} }

Binary file not shown.

Binary file not shown.