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

View File

@ -26,11 +26,11 @@ import javax.swing.border.*;
import java.awt.Component;
import java.awt.Color;
import java.awt.Rectangle;
import java.io.Serializable;
import java.text.*;
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,
HSSFCellStyle.BORDER_NONE,
HSSFCellStyle.BORDER_NONE,
HSSFCellStyle.BORDER_NONE,
HSSFCellStyle.BORDER_NONE,
BorderStyle.NONE,
BorderStyle.NONE,
BorderStyle.NONE,
BorderStyle.NONE,
isSelected);
setBorder(cellBorder);
}

View File

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

View File

@ -62,22 +62,34 @@ public class ToHtml {
private static final String COL_HEAD_CLASS = "colHeader";
private static final String ROW_HEAD_CLASS = "rowHeader";
private static final Map<Short, String> ALIGN = mapFor(ALIGN_LEFT, "left",
ALIGN_CENTER, "center", ALIGN_RIGHT, "right", ALIGN_FILL, "left",
ALIGN_JUSTIFY, "left", ALIGN_CENTER_SELECTION, "center");
private static final Map<Short, String> ALIGN = mapFor(
ALIGN_LEFT, "left",
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(
VERTICAL_BOTTOM, "bottom", VERTICAL_CENTER, "middle", VERTICAL_TOP,
"top");
VERTICAL_BOTTOM, "bottom",
VERTICAL_CENTER, "middle",
VERTICAL_TOP, "top");
private static final Map<Short, String> BORDER = mapFor(BORDER_DASH_DOT,
"dashed 1pt", BORDER_DASH_DOT_DOT, "dashed 1pt", BORDER_DASHED,
"dashed 1pt", BORDER_DOTTED, "dotted 1pt", BORDER_DOUBLE,
"double 3pt", BORDER_HAIR, "solid 1px", BORDER_MEDIUM, "solid 2pt",
BORDER_MEDIUM_DASH_DOT, "dashed 2pt", BORDER_MEDIUM_DASH_DOT_DOT,
"dashed 2pt", BORDER_MEDIUM_DASHED, "dashed 2pt", BORDER_NONE,
"none", BORDER_SLANTED_DASH_DOT, "dashed 2pt", BORDER_THICK,
"solid 3pt", BORDER_THIN, "dashed 1pt");
private static final Map<BorderStyle, String> BORDER = mapFor(
BorderStyle.DASH_DOT, "dashed 1pt",
BorderStyle.DASH_DOT_DOT, "dashed 1pt",
BorderStyle.DASHED, "dashed 1pt",
BorderStyle.DOTTED, "dotted 1pt",
BorderStyle.DOUBLE, "double 3pt",
BorderStyle.HAIR, "solid 1px",
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"})
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.cf.BorderFormatting;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Color;
/**
@ -41,65 +42,80 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
return borderFormatting;
}
public short getBorderBottom() {
return (short)borderFormatting.getBorderBottom();
@Override
public BorderStyle getBorderBottom() {
return BorderStyle.valueOf((short)borderFormatting.getBorderBottom());
}
public short getBorderDiagonal() {
return (short)borderFormatting.getBorderDiagonal();
@Override
public BorderStyle getBorderDiagonal() {
return BorderStyle.valueOf((short)borderFormatting.getBorderDiagonal());
}
public short getBorderLeft() {
return (short)borderFormatting.getBorderLeft();
@Override
public BorderStyle getBorderLeft() {
return BorderStyle.valueOf((short)borderFormatting.getBorderLeft());
}
public short getBorderRight() {
return (short)borderFormatting.getBorderRight();
@Override
public BorderStyle getBorderRight() {
return BorderStyle.valueOf((short)borderFormatting.getBorderRight());
}
public short getBorderTop() {
return (short)borderFormatting.getBorderTop();
@Override
public BorderStyle getBorderTop() {
return BorderStyle.valueOf((short)borderFormatting.getBorderTop());
}
@Override
public short getBottomBorderColor() {
return (short)borderFormatting.getBottomBorderColor();
}
@Override
public HSSFColor getBottomBorderColorColor() {
return workbook.getCustomPalette().getColor(
borderFormatting.getBottomBorderColor()
);
}
@Override
public short getDiagonalBorderColor() {
return (short)borderFormatting.getDiagonalBorderColor();
}
@Override
public HSSFColor getDiagonalBorderColorColor() {
return workbook.getCustomPalette().getColor(
borderFormatting.getDiagonalBorderColor()
);
}
@Override
public short getLeftBorderColor() {
return (short)borderFormatting.getLeftBorderColor();
}
@Override
public HSSFColor getLeftBorderColorColor() {
return workbook.getCustomPalette().getColor(
borderFormatting.getLeftBorderColor()
);
}
@Override
public short getRightBorderColor() {
return (short)borderFormatting.getRightBorderColor();
}
@Override
public HSSFColor getRightBorderColorColor() {
return workbook.getCustomPalette().getColor(
borderFormatting.getRightBorderColor()
);
}
@Override
public short getTopBorderColor() {
return (short)borderFormatting.getTopBorderColor();
}
@Override
public HSSFColor getTopBorderColorColor() {
return workbook.getCustomPalette().getColor(
borderFormatting.getTopBorderColor()
@ -126,6 +142,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
}
}
@Override
public void setBorderBottom(short border) {
borderFormatting.setBorderBottom(border);
if (border != 0) {
@ -134,7 +151,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setBottomBorderModified(false);
}
}
@Override
public void setBorderBottom(BorderStyle border) {
setBorderBottom(border.getCode());
}
@Override
public void setBorderDiagonal(short border) {
borderFormatting.setBorderDiagonal(border);
if (border != 0) {
@ -145,7 +167,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopLeftBottomRightBorderModified(false);
}
}
@Override
public void setBorderDiagonal(BorderStyle border) {
setBorderDiagonal(border.getCode());
}
@Override
public void setBorderLeft(short border) {
borderFormatting.setBorderLeft(border);
if (border != 0) {
@ -154,7 +181,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setLeftBorderModified(false);
}
}
@Override
public void setBorderLeft(BorderStyle border) {
setBorderLeft(border.getCode());
}
@Override
public void setBorderRight(short border) {
borderFormatting.setBorderRight(border);
if (border != 0) {
@ -163,7 +195,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setRightBorderModified(false);
}
}
@Override
public void setBorderRight(BorderStyle border) {
setBorderRight(border.getCode());
}
@Override
public void setBorderTop(short border) {
borderFormatting.setBorderTop(border);
if (border != 0) {
@ -172,7 +209,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopBorderModified(false);
}
}
@Override
public void setBorderTop(BorderStyle border) {
setBorderTop(border.getCode());
}
@Override
public void setBottomBorderColor(short color) {
borderFormatting.setBottomBorderColor(color);
if (color != 0) {
@ -190,6 +232,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
}
}
@Override
public void setDiagonalBorderColor(short color) {
borderFormatting.setDiagonalBorderColor(color);
if (color != 0) {
@ -200,6 +243,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopLeftBottomRightBorderModified(false);
}
}
@Override
public void setDiagonalBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) {
@ -209,6 +253,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
}
}
@Override
public void setLeftBorderColor(short color) {
borderFormatting.setLeftBorderColor(color);
if (color != 0) {
@ -217,6 +262,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setLeftBorderModified(false);
}
}
@Override
public void setLeftBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) {
@ -226,6 +272,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
}
}
@Override
public void setRightBorderColor(short color) {
borderFormatting.setRightBorderColor(color);
if (color != 0) {
@ -234,6 +281,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setRightBorderModified(false);
}
}
@Override
public void setRightBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) {
@ -243,6 +291,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
}
}
@Override
public void setTopBorderColor(short color) {
borderFormatting.setTopBorderColor(color);
if (color != 0) {
@ -251,6 +300,7 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopBorderModified(false);
}
}
@Override
public void setTopBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
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.StyleRecord;
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.Font;
@ -410,6 +411,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderLeft(short border)
@ -419,27 +421,23 @@ public final class HSSFCellStyle implements CellStyle {
}
/**
* get the type of border to use for the left border of the cell
* @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
* set the type of border to use for the left border of the cell
* @param border type
*/
@Override
public short getBorderLeft()
public void setBorderLeft(BorderStyle border)
{
return _format.getBorderLeft();
setBorderLeft(border.getCode());
}
/**
* get the type of border to use for the left border of the cell
* @return border type
*/
@Override
public BorderStyle getBorderLeft()
{
return BorderStyle.valueOf(_format.getBorderLeft());
}
/**
@ -459,6 +457,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderRight(short border)
@ -468,27 +467,23 @@ public final class HSSFCellStyle implements CellStyle {
}
/**
* get the type of border to use for the right border of the cell
* @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
* set the type of border to use for the right border of the cell
* @param border type
*/
@Override
public short getBorderRight()
public void setBorderRight(BorderStyle border)
{
return _format.getBorderRight();
setBorderRight(border.getCode());
}
/**
* get the type of border to use for the right border of the cell
* @return border type
*/
@Override
public BorderStyle getBorderRight()
{
return BorderStyle.valueOf(_format.getBorderRight());
}
/**
@ -508,6 +503,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderTop(short border)
@ -517,27 +513,23 @@ public final class HSSFCellStyle implements CellStyle {
}
/**
* get the type of border to use for the top border of the cell
* @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
* set the type of border to use for the top border of the cell
* @param border type
*/
@Override
public short getBorderTop()
public void setBorderTop(BorderStyle border)
{
return _format.getBorderTop();
setBorderTop(border.getCode());
}
/**
* get the type of border to use for the top border of the cell
* @return border type
*/
@Override
public BorderStyle getBorderTop()
{
return BorderStyle.valueOf(_format.getBorderTop());
}
/**
@ -557,6 +549,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderBottom(short border)
@ -566,27 +559,23 @@ public final class HSSFCellStyle implements CellStyle {
}
/**
* get the type of border to use for the bottom border of the cell
* @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
* set the type of border to use for the bottom border of the cell
* @param border type
*/
@Override
public short getBorderBottom()
public void setBorderBottom(BorderStyle border)
{
return _format.getBorderBottom();
setBorderBottom(border.getCode());
}
/**
* get the type of border to use for the bottom border of the cell
* @return border type
*/
@Override
public BorderStyle getBorderBottom()
{
return BorderStyle.valueOf(_format.getBorderBottom());
}
/**

View File

@ -24,44 +24,86 @@ package org.apache.poi.ss.usermodel;
* of Conditional Formatting settings
*/
public interface BorderFormatting {
/** No border */
/** No border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_NONE = 0x0;
/** Thin border */
/** Thin border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_THIN = 0x1;
/** Medium border */
/** Medium border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_MEDIUM = 0x2;
/** dash border */
/** dash border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_DASHED = 0x3;
/** dot border */
short BORDER_HAIR = 0x4;
/** Thick border */
/** dot 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;
/** double-line border */
/** double-line border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
short BORDER_DOUBLE = 0x6;
/** hair-line border */
short BORDER_DOTTED = 0x7;
/** Medium dashed border */
/** hair-line 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;
/** dash-dot border */
/** dash-dot border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
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;
/** dash-dot-dot border */
/** dash-dot-dot border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
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;
/** slanted dash-dot border */
/** slanted dash-dot border
* @deprecated 3.15 beta 1. Use {@link BorderStyle}
*/
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();
Color getBottomBorderColorColor();
@ -78,36 +120,81 @@ public interface BorderFormatting {
short getTopBorderColor();
Color getTopBorderColorColor();
/**
* Set bottom border.
*
* @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/
void setBorderBottom(short border);
/**
* Set bottom border.
*
* @param border
*/
void setBorderBottom(BorderStyle border);
/**
* Set diagonal border.
*
* @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/
void setBorderDiagonal(short border);
/**
* Set diagonal border.
*
* @param border
*/
void setBorderDiagonal(BorderStyle border);
/**
* Set left border.
*
* @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/
void setBorderLeft(short border);
/**
* Set left border.
*
* @param border
*/
void setBorderLeft(BorderStyle border);
/**
* Set right border.
*
* @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/
void setBorderRight(short border);
/**
* Set right border.
*
* @param border
*/
void setBorderRight(BorderStyle border);
/**
* Set top border.
*
* @param border MUST be a BORDER_* constant
* @deprecated 3.15 beta 1
*/
void setBorderTop(short border);
/**
* Set top border.
*
* @param border
*/
void setBorderTop(BorderStyle border);
void setBottomBorderColor(short 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,
* 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.
*/
public enum BorderStyle {
/**
* No border
* No border (default)
*/
NONE(0x0),
@ -86,9 +86,7 @@ package org.apache.poi.ss.usermodel;
/**
* 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),
/**
@ -96,14 +94,24 @@ package org.apache.poi.ss.usermodel;
*/
SLANTED_DASH_DOT(0xD);
private final short code;
BorderStyle(int code) {
private BorderStyle(int code) {
this.code = (short)code;
}
public short getCode() {
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
* @deprecated Use {@link BorderStyle}
*/
short BORDER_NONE = 0x0;
/**
* Thin border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_THIN = 0x1;
/**
* Medium border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_MEDIUM = 0x2;
/**
* dash border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_DASHED = 0x3;
/**
* dot border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_DOTTED = 0x4;
/**
* Thick border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_THICK = 0x5;
/**
* double-line border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_DOUBLE = 0x6;
/**
* hair-line border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_HAIR = 0x7;
/**
* Medium dashed border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_MEDIUM_DASHED = 0x8;
/**
* dash-dot border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_DASH_DOT = 0x9;
/**
* medium dash-dot border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_MEDIUM_DASH_DOT = 0xA;
/**
* dash-dot-dot border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_DASH_DOT_DOT = 0xB;
/**
* medium dash-dot-dot border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
/**
* slanted dash-dot border
* @deprecated Use {@link BorderStyle}
*/
short BORDER_SLANTED_DASH_DOT = 0xD;
@ -416,30 +430,21 @@ public interface CellStyle {
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
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
* @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 getBorderLeft();
BorderStyle getBorderLeft();
/**
* 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_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
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
* @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 getBorderRight();
BorderStyle getBorderRight();
/**
* 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_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
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
* @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 getBorderTop();
BorderStyle getBorderTop();
/**
* 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_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
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
* @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

View File

@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
@ -277,10 +278,10 @@ public final class CellUtil {
private static Map<String, Object> getFormatProperties(CellStyle style) {
Map<String, Object> properties = new HashMap<String, Object>();
putShort(properties, ALIGNMENT, style.getAlignment());
putShort(properties, BORDER_BOTTOM, style.getBorderBottom());
putShort(properties, BORDER_LEFT, style.getBorderLeft());
putShort(properties, BORDER_RIGHT, style.getBorderRight());
putShort(properties, BORDER_TOP, style.getBorderTop());
putBorderStyle(properties, BORDER_BOTTOM, style.getBorderBottom());
putBorderStyle(properties, BORDER_LEFT, style.getBorderLeft());
putBorderStyle(properties, BORDER_RIGHT, style.getBorderRight());
putBorderStyle(properties, BORDER_TOP, style.getBorderTop());
putShort(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor());
putShort(properties, DATA_FORMAT, style.getDataFormat());
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) {
style.setAlignment(getShort(properties, ALIGNMENT));
style.setBorderBottom(getShort(properties, BORDER_BOTTOM));
style.setBorderLeft(getShort(properties, BORDER_LEFT));
style.setBorderRight(getShort(properties, BORDER_RIGHT));
style.setBorderTop(getShort(properties, BORDER_TOP));
style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
style.setDataFormat(getShort(properties, DATA_FORMAT));
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
@ -346,6 +347,18 @@ public final class CellUtil {
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.
*
@ -374,6 +387,17 @@ public final class CellUtil {
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.
*

View File

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

View File

@ -251,148 +251,85 @@ public class XSSFCellStyle implements CellStyle {
/**
* Get the type of border to use for the bottom border of the cell
*
* @return short - border type
* @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
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
*/
@Override
public short getBorderBottom() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE;
public BorderStyle getBorderBottom() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
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
*
* @return border type as Java enum
* @see BorderStyle
* @deprecated 3.15 beta 1. Use {@link #getBorderBottom}
*/
public BorderStyle getBorderBottomEnum() {
int style = getBorderBottom();
return BorderStyle.values()[style];
return getBorderBottom();
}
/**
* 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}
* @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
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
*/
@Override
public short getBorderLeft() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE;
public BorderStyle getBorderLeft() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
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
*
* @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() {
int style = getBorderLeft();
return BorderStyle.values()[style];
return getBorderLeft();
}
/**
* 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
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
*/
@Override
public short getBorderRight() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE;
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;
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 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() {
int style = getBorderRight();
return BorderStyle.values()[style];
}
/**
* 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}
* @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 getBorderTop() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE;
int idx = (int)_cellXf.getBorderId();
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetTop() ? ct.getTop().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
return getBorderRight();
}
/**
@ -400,9 +337,27 @@ public class XSSFCellStyle implements CellStyle {
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
*/
@Override
public BorderStyle getBorderTop() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetTop() ? ct.getTop().getStyle() : null;
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
*
* @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() {
int style = getBorderTop();
return BorderStyle.values()[style];
return getBorderTop();
}
/**
@ -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_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderBottom(short border) {
@ -869,8 +825,9 @@ public class XSSFCellStyle implements CellStyle {
* @param border - type of border to use
* @see org.apache.poi.ss.usermodel.BorderStyle
*/
@Override
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_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderLeft(short border) {
@ -909,8 +867,9 @@ public class XSSFCellStyle implements CellStyle {
*
* @param border the type of border to use
*/
@Override
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_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderRight(short border) {
@ -950,8 +910,9 @@ public class XSSFCellStyle implements CellStyle {
*
* @param border the type of border to use
*/
@Override
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_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderTop(short border) {
public void setBorderTop(short border) {
CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop();
if(border == BORDER_NONE) ct.unsetTop();
@ -991,8 +953,9 @@ public void setBorderTop(short border) {
*
* @param border the type of border to use
*/
@Override
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
public void testGetSetBorderBottom() {
//default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderBottom());
assertEquals(BorderStyle.NONE, cellStyle.getBorderBottom());
int num = stylesTable.getBorders().size();
cellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderBottom());
cellStyle.setBorderBottom(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@ -121,15 +121,15 @@ public class TestXSSFCellStyle {
num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderBottom());
cellStyle.setBorderBottom(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <bottom> element
cellStyle.setBorderBottom(CellStyle.BORDER_NONE);
cellStyle.setBorderBottom(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size());
borderId = (int)cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
@ -139,11 +139,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderRight() {
//default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderRight());
assertEquals(BorderStyle.NONE, cellStyle.getBorderRight());
int num = stylesTable.getBorders().size();
cellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderRight());
cellStyle.setBorderRight(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@ -156,15 +156,15 @@ public class TestXSSFCellStyle {
num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderRight());
cellStyle.setBorderRight(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <right> element
cellStyle.setBorderRight(CellStyle.BORDER_NONE);
cellStyle.setBorderRight(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size());
borderId = (int)cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
@ -174,11 +174,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderLeft() {
//default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderLeft());
assertEquals(BorderStyle.NONE, cellStyle.getBorderLeft());
int num = stylesTable.getBorders().size();
cellStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderLeft());
cellStyle.setBorderLeft(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@ -191,15 +191,15 @@ public class TestXSSFCellStyle {
num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderLeft());
cellStyle.setBorderLeft(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <left> element
cellStyle.setBorderLeft(CellStyle.BORDER_NONE);
cellStyle.setBorderLeft(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size());
borderId = (int)cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
@ -209,11 +209,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderTop() {
//default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderTop());
assertEquals(BorderStyle.NONE, cellStyle.getBorderTop());
int num = stylesTable.getBorders().size();
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop());
cellStyle.setBorderTop(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@ -226,162 +226,109 @@ public class TestXSSFCellStyle {
num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop());
cellStyle.setBorderTop(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <top> element
cellStyle.setBorderTop(CellStyle.BORDER_NONE);
cellStyle.setBorderTop(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size());
borderId = (int)cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertFalse(ctBorder.isSetTop());
}
@Test
public void testGetSetBorderThin() {
cellStyle.setBorderTop(CellStyle.BORDER_THIN);
assertEquals(CellStyle.BORDER_THIN, cellStyle.getBorderTop());
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(STBorderStyle.THIN, ctBorder.getTop().getStyle());
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
public void testGetSetBorderThin() {
testGetSetBorderXMLBean(BorderStyle.THIN, STBorderStyle.THIN);
}
@Test
public void testGetSetBorderMedium() {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, 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, 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());
testGetSetBorderXMLBean(BorderStyle.MEDIUM, STBorderStyle.MEDIUM);
}
@Test
public void testGetSetBorderDashed() {
cellStyle.setBorderTop(CellStyle.BORDER_DASHED);
assertEquals(CellStyle.BORDER_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.DASHED, ctBorder.getTop().getStyle());
testGetSetBorderXMLBean(BorderStyle.DASHED, STBorderStyle.DASHED);
}
@Test
public void testGetSetBorderDashDot() {
cellStyle.setBorderTop(CellStyle.BORDER_DASH_DOT);
assertEquals(CellStyle.BORDER_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.DASH_DOT, ctBorder.getTop().getStyle());
public void testGetSetBorderDotted() {
testGetSetBorderXMLBean(BorderStyle.DOTTED, STBorderStyle.DOTTED);
}
@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());
public void testGetSetBorderThick() {
testGetSetBorderXMLBean(BorderStyle.THICK, STBorderStyle.THICK);
}
@Test
public void testGetSetBorderDouble() {
cellStyle.setBorderTop(CellStyle.BORDER_DOUBLE);
assertEquals(CellStyle.BORDER_DOUBLE, 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.DOUBLE, ctBorder.getTop().getStyle());
testGetSetBorderXMLBean(BorderStyle.DOUBLE, STBorderStyle.DOUBLE);
}
@Test
public void testGetSetBorderHair() {
testGetSetBorderXMLBean(BorderStyle.HAIR, STBorderStyle.HAIR);
}
@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
@ -780,21 +727,21 @@ public class TestXSSFCellStyle {
assertEquals(2, wb.getNumberOfFonts());
XSSFCellStyle orig = wb.createCellStyle();
orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
orig.setAlignment(CellStyle.ALIGN_RIGHT);
orig.setFont(fnt);
orig.setDataFormat((short)18);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment());
assertTrue(CellStyle.ALIGN_RIGHT == orig.getAlignment());
assertTrue(fnt == orig.getFont());
assertTrue(18 == orig.getDataFormat());
XSSFCellStyle clone = wb.createCellStyle();
assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertFalse(CellStyle.ALIGN_RIGHT == clone.getAlignment());
assertFalse(fnt == clone.getFont());
assertFalse(18 == clone.getDataFormat());
clone.cloneStyleFrom(orig);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertTrue(CellStyle.ALIGN_RIGHT == clone.getAlignment());
assertTrue(fnt == clone.getFont());
assertTrue(18 == clone.getDataFormat());
assertEquals(2, wb.getNumberOfFonts());
@ -1104,5 +1051,7 @@ public class TestXSSFCellStyle {
cellStyle.setRightBorderColor(null);
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.util.HSSFColor;
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.util.Beta;
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;
switch ( xlsBorder )
{
case HSSFCellStyle.BORDER_NONE:
case NONE:
borderStyle = "none";
break;
case HSSFCellStyle.BORDER_DASH_DOT:
case HSSFCellStyle.BORDER_DASH_DOT_DOT:
case HSSFCellStyle.BORDER_DOTTED:
case HSSFCellStyle.BORDER_HAIR:
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT:
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT:
case HSSFCellStyle.BORDER_SLANTED_DASH_DOT:
case DASH_DOT:
case DASH_DOT_DOT:
case DOTTED:
case HAIR:
case MEDIUM_DASH_DOT:
case MEDIUM_DASH_DOT_DOT:
case SLANTED_DASH_DOT:
borderStyle = "dotted";
break;
case HSSFCellStyle.BORDER_DASHED:
case HSSFCellStyle.BORDER_MEDIUM_DASHED:
case DASHED:
case MEDIUM_DASHED:
borderStyle = "dashed";
break;
case HSSFCellStyle.BORDER_DOUBLE:
case DOUBLE:
borderStyle = "double";
break;
default:
@ -97,17 +98,17 @@ public class AbstractExcelUtils
return borderStyle;
}
public static String getBorderWidth( short xlsBorder )
public static String getBorderWidth( BorderStyle xlsBorder )
{
final String borderWidth;
switch ( xlsBorder )
{
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT:
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT:
case HSSFCellStyle.BORDER_MEDIUM_DASHED:
case MEDIUM_DASH_DOT:
case MEDIUM_DASH_DOT_DOT:
case MEDIUM_DASHED:
borderWidth = "2pt";
break;
case HSSFCellStyle.BORDER_THICK:
case THICK:
borderWidth = "thick";
break;
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.FontReplacer.Triplet;
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.util.CellRangeAddress;
import org.apache.poi.util.Beta;
@ -192,10 +193,10 @@ public class ExcelToFoConverter extends AbstractExcelConverter
protected boolean isEmptyStyle( CellStyle cellStyle ) {
return cellStyle == null || (
cellStyle.getFillPattern() == 0
&& cellStyle.getBorderTop() == HSSFCellStyle.BORDER_NONE
&& cellStyle.getBorderRight() == HSSFCellStyle.BORDER_NONE
&& cellStyle.getBorderBottom() == HSSFCellStyle.BORDER_NONE
&& cellStyle.getBorderLeft() == HSSFCellStyle.BORDER_NONE
&& cellStyle.getBorderTop() == BorderStyle.NONE
&& cellStyle.getBorderRight() == BorderStyle.NONE
&& cellStyle.getBorderBottom() == BorderStyle.NONE
&& cellStyle.getBorderLeft() == BorderStyle.NONE
);
}
@ -374,9 +375,9 @@ public class ExcelToFoConverter extends AbstractExcelConverter
}
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;
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.hwpf.converter.HtmlDocumentFacade;
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.util.Beta;
import org.apache.poi.util.POILogFactory;
@ -190,9 +191,9 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
}
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;
}

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.Ptg;
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.CellStyle;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
@ -2564,7 +2565,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(0);
HSSFCellStyle rstyle = row.getRowStyle();
assertEquals(rstyle.getBorderBottom(), CellStyle.BORDER_DOUBLE);
assertEquals(BorderStyle.DOUBLE, rstyle.getBorderBottom());
wb.close();
}

View File

@ -24,6 +24,7 @@ import java.util.Calendar;
import java.util.Date;
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.CellStyle;
import org.apache.poi.ss.usermodel.Font;
@ -180,10 +181,10 @@ public final class TestCellStyle extends TestCase {
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
cs.setBorderBottom(BorderStyle.THIN);
cs.setBorderLeft(BorderStyle.THIN);
cs.setBorderRight(BorderStyle.THIN);
cs.setBorderTop(BorderStyle.THIN);
cs.setFillForegroundColor(( short ) 0xA);
cs.setFillPattern(( short ) 1);
fnt.setColor(( short ) 0xf);
@ -346,40 +347,40 @@ public final class TestCellStyle extends TestCase {
HSSFCellStyle cs;
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();
assertEquals(CellStyle.BORDER_DOTTED, cs.getBorderRight());
assertEquals(BorderStyle.DOTTED, cs.getBorderRight());
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();
assertEquals(CellStyle.BORDER_DASHED, cs.getBorderRight());
assertEquals(BorderStyle.DASHED, cs.getBorderRight());
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();
assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT, cs.getBorderRight());
assertEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, cs.getBorderRight());
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();
assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT, cs.getBorderRight());
assertEquals(BorderStyle.MEDIUM_DASH_DOT, cs.getBorderRight());
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();
assertEquals(CellStyle.BORDER_MEDIUM, cs.getBorderRight());
assertEquals(BorderStyle.MEDIUM, cs.getBorderRight());
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();
assertEquals(CellStyle.BORDER_DOUBLE, cs.getBorderRight());
assertEquals(BorderStyle.DOUBLE, cs.getBorderRight());
}
public void testShrinkToFit() {
@ -485,7 +486,7 @@ public final class TestCellStyle extends TestCase {
font.setColor(Font.COLOR_RED);
CellStyle style = wb.createCellStyle();
style.setBorderBottom(CellStyle.BORDER_DOTTED);
style.setBorderBottom(BorderStyle.DOTTED);
style.setFont(font);
Cell cell = row.createCell(0);
@ -498,7 +499,7 @@ public final class TestCellStyle extends TestCase {
newCell.setCellValue("2testtext2");
CellStyle newStyle = newCell.getCellStyle();
assertEquals(CellStyle.BORDER_DOTTED, newStyle.getBorderBottom());
assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottom());
assertEquals(Font.COLOR_RED, ((HSSFCellStyle)newStyle).getFont(wb).getColor());
// OutputStream out = new FileOutputStream("/tmp/56959.xls");

View File

@ -16,6 +16,8 @@
==================================================================== */
package org.apache.poi.hssf.usermodel;
import org.apache.poi.ss.usermodel.BorderStyle;
import junit.framework.TestCase;
public final class TestHSSFOptimiser extends TestCase {
@ -278,13 +280,13 @@ public final class TestHSSFOptimiser extends TestCase {
assertEquals(21, wb.getNumCellStyles());
HSSFCellStyle cs1 = wb.createCellStyle();
cs1.setBorderBottom(HSSFCellStyle.BORDER_THICK);
cs1.setBorderBottom(BorderStyle.THICK);
HSSFCellStyle cs2 = wb.createCellStyle();
cs2.setBorderBottom(HSSFCellStyle.BORDER_DASH_DOT);
cs2.setBorderBottom(BorderStyle.DASH_DOT);
HSSFCellStyle cs3 = wb.createCellStyle(); // = cs1
cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK);
cs3.setBorderBottom(BorderStyle.THICK);
assertEquals(24, wb.getNumCellStyles());
@ -306,8 +308,8 @@ public final class TestHSSFOptimiser extends TestCase {
// Check
assertEquals(23, wb.getNumCellStyles());
assertEquals(HSSFCellStyle.BORDER_THICK, r.getCell(0).getCellStyle().getBorderBottom());
assertEquals(HSSFCellStyle.BORDER_DASH_DOT, r.getCell(1).getCellStyle().getBorderBottom());
assertEquals(HSSFCellStyle.BORDER_THICK, r.getCell(2).getCellStyle().getBorderBottom());
assertEquals(BorderStyle.THICK, r.getCell(0).getCellStyle().getBorderBottom());
assertEquals(BorderStyle.DASH_DOT, r.getCell(1).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 org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BorderStyle;
/**
* Class to test row styling functionality
@ -110,10 +111,10 @@ public final class TestRowStyle extends TestCase {
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
cs.setBorderBottom(BorderStyle.THIN);
cs.setBorderLeft(BorderStyle.THIN);
cs.setBorderRight(BorderStyle.THIN);
cs.setBorderTop(BorderStyle.THIN);
cs.setFillForegroundColor(( short ) 0xA);
cs.setFillPattern(( short ) 1);
fnt.setColor(( short ) 0xf);
@ -150,12 +151,12 @@ public final class TestRowStyle extends TestCase {
assertNotNull("Row is not null", r);
cs = r.getRowStyle();
assertEquals("FillForegroundColor for row: ", cs.getBorderBottom(), HSSFCellStyle.BORDER_THIN);
assertEquals("FillPattern for row: ", cs.getBorderLeft(), HSSFCellStyle.BORDER_THIN);
assertEquals("FillForegroundColor for row: ", cs.getBorderRight(), HSSFCellStyle.BORDER_THIN);
assertEquals("FillPattern for row: ", cs.getBorderTop(), HSSFCellStyle.BORDER_THIN);
assertEquals("FillForegroundColor for row: ", cs.getFillForegroundColor(), 0xA);
assertEquals("FillPattern for row: ", cs.getFillPattern(), (short) 0x1);
assertEquals("Bottom Border Style for row:", BorderStyle.THIN, cs.getBorderBottom());
assertEquals("Left Border Style for row:", BorderStyle.THIN, cs.getBorderLeft());
assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRight());
assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTop());
assertEquals("FillForegroundColor for row:", 0xA, cs.getFillForegroundColor());
assertEquals("FillPattern for row:", 0x1, cs.getFillPattern());
rownum++;
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");
cs.setFillBackgroundColor((short)3);
cs.setFont(f);
cs.setBorderTop((short)1);
cs.setBorderRight((short)1);
cs.setBorderLeft((short)1);
cs.setBorderBottom((short)1);
cs.setBorderTop(BorderStyle.THIN);
cs.setBorderRight(BorderStyle.THIN);
cs.setBorderLeft(BorderStyle.THIN);
cs.setBorderBottom(BorderStyle.THIN);
r = s.createRow(0);
c=r.createCell(0);
@ -270,15 +270,15 @@ public abstract class BaseTestCell {
r = s.getRow(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();
assertNotNull("Formula Cell Style", cs);
assertTrue("Font Index Matches", (cs.getFontIndex() == f.getIndex()));
assertTrue("Top Border", (cs.getBorderTop() == (short)1));
assertTrue("Left Border", (cs.getBorderLeft() == (short)1));
assertTrue("Right Border", (cs.getBorderRight() == (short)1));
assertTrue("Bottom Border", (cs.getBorderBottom() == (short)1));
assertEquals("Font Index Matches", f.getIndex(), cs.getFontIndex());
assertEquals("Top Border", BorderStyle.THIN, cs.getBorderTop());
assertEquals("Left Border", BorderStyle.THIN, cs.getBorderLeft());
assertEquals("Right Border", BorderStyle.THIN, cs.getBorderRight());
assertEquals("Bottom Border", BorderStyle.THIN, cs.getBorderBottom());
wb2.close();
}

View File

@ -323,10 +323,10 @@ public abstract class BaseTestConditionalFormatting {
fontFmt.setFontStyle(true, false);
BorderFormatting bordFmt = rule1.createBorderFormatting();
bordFmt.setBorderBottom(BorderFormatting.BORDER_THIN);
bordFmt.setBorderTop(BorderFormatting.BORDER_THICK);
bordFmt.setBorderLeft(BorderFormatting.BORDER_DASHED);
bordFmt.setBorderRight(BorderFormatting.BORDER_DOTTED);
bordFmt.setBorderBottom(BorderStyle.THIN);
bordFmt.setBorderTop(BorderStyle.THICK);
bordFmt.setBorderLeft(BorderStyle.DASHED);
bordFmt.setBorderRight(BorderStyle.DOTTED);
PatternFormatting patternFmt = rule1.createPatternFormatting();
patternFmt.setFillBackgroundColor(IndexedColors.YELLOW.index);
@ -376,10 +376,10 @@ public abstract class BaseTestConditionalFormatting {
BorderFormatting r1bf = rule1.getBorderFormatting();
assertNotNull(r1bf);
assertEquals(BorderFormatting.BORDER_THIN, r1bf.getBorderBottom());
assertEquals(BorderFormatting.BORDER_THICK,r1bf.getBorderTop());
assertEquals(BorderFormatting.BORDER_DASHED,r1bf.getBorderLeft());
assertEquals(BorderFormatting.BORDER_DOTTED,r1bf.getBorderRight());
assertEquals(BorderStyle.THIN, r1bf.getBorderBottom());
assertEquals(BorderStyle.THICK,r1bf.getBorderTop());
assertEquals(BorderStyle.DASHED,r1bf.getBorderLeft());
assertEquals(BorderStyle.DOTTED,r1bf.getBorderRight());
PatternFormatting r1pf = rule1.getPatternFormatting();
assertNotNull(r1pf);
@ -453,7 +453,7 @@ public abstract class BaseTestConditionalFormatting {
ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(
ComparisonOperator.BETWEEN, "SUM(A10:A15)", "1+SUM(B16:B30)");
BorderFormatting borderFmt = rule2.createBorderFormatting();
borderFmt.setBorderDiagonal((short) 2);
borderFmt.setBorderDiagonal(BorderStyle.MEDIUM);
CellRangeAddress [] regions = {
new CellRangeAddress(2, 4, 0, 0), // A3:A5
@ -1020,6 +1020,38 @@ public abstract class BaseTestConditionalFormatting {
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
public void testCreateBorderFormatting() throws IOException {
Workbook workbook = _testDataProvider.createWorkbook();
@ -1030,37 +1062,37 @@ public abstract class BaseTestConditionalFormatting {
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "7");
BorderFormatting borderFmt = rule1.createBorderFormatting();
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderBottom());
borderFmt.setBorderBottom(BorderFormatting.BORDER_DOTTED);
assertEquals(BorderFormatting.BORDER_DOTTED, borderFmt.getBorderBottom());
borderFmt.setBorderBottom(BorderFormatting.BORDER_NONE);
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderBottom());
borderFmt.setBorderBottom(BorderFormatting.BORDER_THICK);
assertEquals(BorderFormatting.BORDER_THICK, borderFmt.getBorderBottom());
assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom());
borderFmt.setBorderBottom(BorderStyle.DOTTED);
assertEquals(BorderStyle.DOTTED, borderFmt.getBorderBottom());
borderFmt.setBorderBottom(BorderStyle.NONE);
assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom());
borderFmt.setBorderBottom(BorderStyle.THICK);
assertEquals(BorderStyle.THICK, borderFmt.getBorderBottom());
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderTop());
borderFmt.setBorderTop(BorderFormatting.BORDER_DOTTED);
assertEquals(BorderFormatting.BORDER_DOTTED, borderFmt.getBorderTop());
borderFmt.setBorderTop(BorderFormatting.BORDER_NONE);
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderTop());
borderFmt.setBorderTop(BorderFormatting.BORDER_THICK);
assertEquals(BorderFormatting.BORDER_THICK, borderFmt.getBorderTop());
assertEquals(BorderStyle.NONE, borderFmt.getBorderTop());
borderFmt.setBorderTop(BorderStyle.DOTTED);
assertEquals(BorderStyle.DOTTED, borderFmt.getBorderTop());
borderFmt.setBorderTop(BorderStyle.NONE);
assertEquals(BorderStyle.NONE, borderFmt.getBorderTop());
borderFmt.setBorderTop(BorderStyle.THICK);
assertEquals(BorderStyle.THICK, borderFmt.getBorderTop());
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderLeft());
borderFmt.setBorderLeft(BorderFormatting.BORDER_DOTTED);
assertEquals(BorderFormatting.BORDER_DOTTED, borderFmt.getBorderLeft());
borderFmt.setBorderLeft(BorderFormatting.BORDER_NONE);
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderLeft());
borderFmt.setBorderLeft(BorderFormatting.BORDER_THIN);
assertEquals(BorderFormatting.BORDER_THIN, borderFmt.getBorderLeft());
assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft());
borderFmt.setBorderLeft(BorderStyle.DOTTED);
assertEquals(BorderStyle.DOTTED, borderFmt.getBorderLeft());
borderFmt.setBorderLeft(BorderStyle.NONE);
assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft());
borderFmt.setBorderLeft(BorderStyle.THIN);
assertEquals(BorderStyle.THIN, borderFmt.getBorderLeft());
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderRight());
borderFmt.setBorderRight(BorderFormatting.BORDER_DOTTED);
assertEquals(BorderFormatting.BORDER_DOTTED, borderFmt.getBorderRight());
borderFmt.setBorderRight(BorderFormatting.BORDER_NONE);
assertEquals(BorderFormatting.BORDER_NONE, borderFmt.getBorderRight());
borderFmt.setBorderRight(BorderFormatting.BORDER_HAIR);
assertEquals(BorderFormatting.BORDER_HAIR, borderFmt.getBorderRight());
assertEquals(BorderStyle.NONE, borderFmt.getBorderRight());
borderFmt.setBorderRight(BorderStyle.DOTTED);
assertEquals(BorderStyle.DOTTED, borderFmt.getBorderRight());
borderFmt.setBorderRight(BorderStyle.NONE);
assertEquals(BorderStyle.NONE, borderFmt.getBorderRight());
borderFmt.setBorderRight(BorderStyle.HAIR);
assertEquals(BorderStyle.HAIR, borderFmt.getBorderRight());
ConditionalFormattingRule [] cfRules = { rule1 };
@ -1076,10 +1108,10 @@ public abstract class BaseTestConditionalFormatting {
BorderFormatting r1fp = cf.getRule(0).getBorderFormatting();
assertNotNull(r1fp);
assertEquals(BorderFormatting.BORDER_THICK, r1fp.getBorderBottom());
assertEquals(BorderFormatting.BORDER_THICK, r1fp.getBorderTop());
assertEquals(BorderFormatting.BORDER_THIN, r1fp.getBorderLeft());
assertEquals(BorderFormatting.BORDER_HAIR, r1fp.getBorderRight());
assertEquals(BorderStyle.THICK, r1fp.getBorderBottom());
assertEquals(BorderStyle.THICK, r1fp.getBorderTop());
assertEquals(BorderStyle.THIN, r1fp.getBorderLeft());
assertEquals(BorderStyle.HAIR, r1fp.getBorderRight());
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 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.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;
/**
@ -53,13 +53,13 @@ public final class TestCellUtil {
// Add a border should create a new style
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();
assertEquals(styCnt2, styCnt1+1);
// Add same border to another cell, should not create another style
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();
assertEquals(styCnt3, styCnt2);
@ -76,19 +76,19 @@ public final class TestCellUtil {
// Add multiple border properties to cell should create a single new style
int styCnt1 = wb.getNumCellStyles();
Map<String, Object> props = new HashMap<String, Object>();
props.put(CellUtil.BORDER_TOP, CellStyle.BORDER_THIN);
props.put(CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN);
props.put(CellUtil.BORDER_LEFT, CellStyle.BORDER_THIN);
props.put(CellUtil.BORDER_RIGHT, CellStyle.BORDER_THIN);
props.put(CellUtil.BORDER_TOP, BorderStyle.THIN);
props.put(CellUtil.BORDER_BOTTOM, BorderStyle.THIN);
props.put(CellUtil.BORDER_LEFT, BorderStyle.THIN);
props.put(CellUtil.BORDER_RIGHT, BorderStyle.THIN);
CellUtil.setCellStyleProperties(c, props);
int styCnt2 = wb.getNumCellStyles();
assertEquals(styCnt2, styCnt1+1);
assertEquals(styCnt1+1, styCnt2);
// Add same border another to same cell, should not create another style
c = r.createCell(1);
CellUtil.setCellStyleProperties(c, props);
int styCnt3 = wb.getNumCellStyles();
assertEquals(styCnt3, styCnt2);
assertEquals(styCnt2, styCnt3);
wb.close();
}

Binary file not shown.

Binary file not shown.