properties, CellPropertyType property, Object value) {
+ properties.put(property, value);
}
/**
@@ -851,24 +1083,25 @@ public final class CellUtil {
static {
unicodeMappings = new UnicodeMapping[] {
- um("alpha", "\u03B1" ),
- um("beta", "\u03B2" ),
- um("gamma", "\u03B3" ),
- um("delta", "\u03B4" ),
- um("epsilon", "\u03B5" ),
- um("zeta", "\u03B6" ),
- um("eta", "\u03B7" ),
- um("theta", "\u03B8" ),
- um("iota", "\u03B9" ),
- um("kappa", "\u03BA" ),
- um("lambda", "\u03BB" ),
- um("mu", "\u03BC" ),
- um("nu", "\u03BD" ),
- um("xi", "\u03BE" ),
- um("omicron", "\u03BF" ),
+ um("alpha", "\u03B1" ),
+ um("beta", "\u03B2" ),
+ um("gamma", "\u03B3" ),
+ um("delta", "\u03B4" ),
+ um("epsilon", "\u03B5" ),
+ um("zeta", "\u03B6" ),
+ um("eta", "\u03B7" ),
+ um("theta", "\u03B8" ),
+ um("iota", "\u03B9" ),
+ um("kappa", "\u03BA" ),
+ um("lambda", "\u03BB" ),
+ um("mu", "\u03BC" ),
+ um("nu", "\u03BD" ),
+ um("xi", "\u03BE" ),
+ um("omicron", "\u03BF" ),
};
}
+
private static UnicodeMapping um(String entityName, String resolvedValue) {
return new UnicodeMapping(entityName, resolvedValue);
}
diff --git a/poi/src/main/java/org/apache/poi/ss/util/PropertyTemplate.java b/poi/src/main/java/org/apache/poi/ss/util/PropertyTemplate.java
index c9aa9e835e..2f74af55d7 100644
--- a/poi/src/main/java/org/apache/poi/ss/util/PropertyTemplate.java
+++ b/poi/src/main/java/org/apache/poi/ss/util/PropertyTemplate.java
@@ -17,21 +17,23 @@
package org.apache.poi.ss.util;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.SpreadsheetVersion;
+
import org.apache.poi.ss.usermodel.BorderExtent;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellPropertyType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
/**
*
* A PropertyTemplate is a template that can be applied to any sheet in
@@ -57,7 +59,7 @@ public final class PropertyTemplate {
* This is a list of cell properties for one shot application to a range of
* cells at a later time.
*/
- private final Map> _propertyTemplate;
+ private final Map> _propertyTemplate;
/**
* Create a PropertyTemplate object
@@ -73,16 +75,16 @@ public final class PropertyTemplate {
*/
public PropertyTemplate(PropertyTemplate template) {
this();
- for(Map.Entry> entry : template.getTemplate().entrySet()) {
+ for (Map.Entry> entry : template.getTemplate().entrySet()) {
_propertyTemplate.put(new CellAddress(entry.getKey()), cloneCellProperties(entry.getValue()));
}
}
- private Map> getTemplate() {
+ private Map> getTemplate() {
return _propertyTemplate;
}
- private static Map cloneCellProperties(Map properties) {
+ private static Map cloneCellProperties(Map properties) {
return new HashMap<>(properties);
}
@@ -101,52 +103,52 @@ public final class PropertyTemplate {
* applied.
*/
public void drawBorders(CellRangeAddress range, BorderStyle borderType,
- BorderExtent extent) {
+ BorderExtent extent) {
switch (extent) {
- case NONE:
- removeBorders(range);
- break;
- case ALL:
- drawHorizontalBorders(range, borderType, BorderExtent.ALL);
- drawVerticalBorders(range, borderType, BorderExtent.ALL);
- break;
- case INSIDE:
- drawHorizontalBorders(range, borderType, BorderExtent.INSIDE);
- drawVerticalBorders(range, borderType, BorderExtent.INSIDE);
- break;
- case OUTSIDE:
- drawOutsideBorders(range, borderType, BorderExtent.ALL);
- break;
- case TOP:
- drawTopBorder(range, borderType);
- break;
- case BOTTOM:
- drawBottomBorder(range, borderType);
- break;
- case LEFT:
- drawLeftBorder(range, borderType);
- break;
- case RIGHT:
- drawRightBorder(range, borderType);
- break;
- case HORIZONTAL:
- drawHorizontalBorders(range, borderType, BorderExtent.ALL);
- break;
- case INSIDE_HORIZONTAL:
- drawHorizontalBorders(range, borderType, BorderExtent.INSIDE);
- break;
- case OUTSIDE_HORIZONTAL:
- drawOutsideBorders(range, borderType, BorderExtent.HORIZONTAL);
- break;
- case VERTICAL:
- drawVerticalBorders(range, borderType, BorderExtent.ALL);
- break;
- case INSIDE_VERTICAL:
- drawVerticalBorders(range, borderType, BorderExtent.INSIDE);
- break;
- case OUTSIDE_VERTICAL:
- drawOutsideBorders(range, borderType, BorderExtent.VERTICAL);
- break;
+ case NONE:
+ removeBorders(range);
+ break;
+ case ALL:
+ drawHorizontalBorders(range, borderType, BorderExtent.ALL);
+ drawVerticalBorders(range, borderType, BorderExtent.ALL);
+ break;
+ case INSIDE:
+ drawHorizontalBorders(range, borderType, BorderExtent.INSIDE);
+ drawVerticalBorders(range, borderType, BorderExtent.INSIDE);
+ break;
+ case OUTSIDE:
+ drawOutsideBorders(range, borderType, BorderExtent.ALL);
+ break;
+ case TOP:
+ drawTopBorder(range, borderType);
+ break;
+ case BOTTOM:
+ drawBottomBorder(range, borderType);
+ break;
+ case LEFT:
+ drawLeftBorder(range, borderType);
+ break;
+ case RIGHT:
+ drawRightBorder(range, borderType);
+ break;
+ case HORIZONTAL:
+ drawHorizontalBorders(range, borderType, BorderExtent.ALL);
+ break;
+ case INSIDE_HORIZONTAL:
+ drawHorizontalBorders(range, borderType, BorderExtent.INSIDE);
+ break;
+ case OUTSIDE_HORIZONTAL:
+ drawOutsideBorders(range, borderType, BorderExtent.HORIZONTAL);
+ break;
+ case VERTICAL:
+ drawVerticalBorders(range, borderType, BorderExtent.ALL);
+ break;
+ case INSIDE_VERTICAL:
+ drawVerticalBorders(range, borderType, BorderExtent.INSIDE);
+ break;
+ case OUTSIDE_VERTICAL:
+ drawOutsideBorders(range, borderType, BorderExtent.VERTICAL);
+ break;
}
}
@@ -168,7 +170,7 @@ public final class PropertyTemplate {
* applied.
*/
public void drawBorders(CellRangeAddress range, BorderStyle borderType,
- short color, BorderExtent extent) {
+ short color, BorderExtent extent) {
drawBorders(range, borderType, extent);
if (borderType != BorderStyle.NONE) {
drawBorderColors(range, color, extent);
@@ -191,9 +193,9 @@ public final class PropertyTemplate {
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
- addProperty(row, i, CellUtil.BORDER_TOP, borderType);
+ addProperty(row, i, CellPropertyType.BORDER_TOP, borderType);
if (borderType == BorderStyle.NONE && row > 0) {
- addProperty(row - 1, i, CellUtil.BORDER_BOTTOM, borderType);
+ addProperty(row - 1, i, CellPropertyType.BORDER_BOTTOM, borderType);
}
}
}
@@ -210,15 +212,15 @@ public final class PropertyTemplate {
* - Type of border to draw. {@link BorderStyle}.
*/
private void drawBottomBorder(CellRangeAddress range,
- BorderStyle borderType) {
+ BorderStyle borderType) {
int row = range.getLastRow();
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
- addProperty(row, i, CellUtil.BORDER_BOTTOM, borderType);
+ addProperty(row, i, CellPropertyType.BORDER_BOTTOM, borderType);
if (borderType == BorderStyle.NONE
&& row < SpreadsheetVersion.EXCEL2007.getMaxRows() - 1) {
- addProperty(row + 1, i, CellUtil.BORDER_TOP, borderType);
+ addProperty(row + 1, i, CellPropertyType.BORDER_TOP, borderType);
}
}
}
@@ -235,14 +237,14 @@ public final class PropertyTemplate {
* - Type of border to draw. {@link BorderStyle}.
*/
private void drawLeftBorder(CellRangeAddress range,
- BorderStyle borderType) {
+ BorderStyle borderType) {
int firstRow = range.getFirstRow();
int lastRow = range.getLastRow();
int col = range.getFirstColumn();
for (int i = firstRow; i <= lastRow; i++) {
- addProperty(i, col, CellUtil.BORDER_LEFT, borderType);
+ addProperty(i, col, CellPropertyType.BORDER_LEFT, borderType);
if (borderType == BorderStyle.NONE && col > 0) {
- addProperty(i, col - 1, CellUtil.BORDER_RIGHT, borderType);
+ addProperty(i, col - 1, CellPropertyType.BORDER_RIGHT, borderType);
}
}
}
@@ -259,15 +261,15 @@ public final class PropertyTemplate {
* - Type of border to draw. {@link BorderStyle}.
*/
private void drawRightBorder(CellRangeAddress range,
- BorderStyle borderType) {
+ BorderStyle borderType) {
int firstRow = range.getFirstRow();
int lastRow = range.getLastRow();
int col = range.getLastColumn();
for (int i = firstRow; i <= lastRow; i++) {
- addProperty(i, col, CellUtil.BORDER_RIGHT, borderType);
+ addProperty(i, col, CellPropertyType.BORDER_RIGHT, borderType);
if (borderType == BorderStyle.NONE
&& col < SpreadsheetVersion.EXCEL2007.getMaxColumns() - 1) {
- addProperty(i, col + 1, CellUtil.BORDER_LEFT, borderType);
+ addProperty(i, col + 1, CellPropertyType.BORDER_LEFT, borderType);
}
}
}
@@ -292,23 +294,23 @@ public final class PropertyTemplate {
*
*/
private void drawOutsideBorders(CellRangeAddress range,
- BorderStyle borderType, BorderExtent extent) {
+ BorderStyle borderType, BorderExtent extent) {
switch (extent) {
- case ALL:
- case HORIZONTAL:
- case VERTICAL:
- if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) {
- drawTopBorder(range, borderType);
- drawBottomBorder(range, borderType);
- }
- if (extent == BorderExtent.ALL || extent == BorderExtent.VERTICAL) {
- drawLeftBorder(range, borderType);
- drawRightBorder(range, borderType);
- }
- break;
- default:
- throw new IllegalArgumentException(
- "Unsupported PropertyTemplate.Extent, valid Extents are ALL, HORIZONTAL, and VERTICAL");
+ case ALL:
+ case HORIZONTAL:
+ case VERTICAL:
+ if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) {
+ drawTopBorder(range, borderType);
+ drawBottomBorder(range, borderType);
+ }
+ if (extent == BorderExtent.ALL || extent == BorderExtent.VERTICAL) {
+ drawLeftBorder(range, borderType);
+ drawRightBorder(range, borderType);
+ }
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported PropertyTemplate.Extent, valid Extents are ALL, HORIZONTAL, and VERTICAL");
}
}
@@ -331,28 +333,28 @@ public final class PropertyTemplate {
*
*/
private void drawHorizontalBorders(CellRangeAddress range,
- BorderStyle borderType, BorderExtent extent) {
+ BorderStyle borderType, BorderExtent extent) {
switch (extent) {
- case ALL:
- case INSIDE:
- int firstRow = range.getFirstRow();
- int lastRow = range.getLastRow();
- int firstCol = range.getFirstColumn();
- int lastCol = range.getLastColumn();
- for (int i = firstRow; i <= lastRow; i++) {
- CellRangeAddress row = new CellRangeAddress(i, i, firstCol,
- lastCol);
- if (extent == BorderExtent.ALL || i > firstRow) {
- drawTopBorder(row, borderType);
- }
- if (extent == BorderExtent.ALL || i < lastRow) {
- drawBottomBorder(row, borderType);
+ case ALL:
+ case INSIDE:
+ int firstRow = range.getFirstRow();
+ int lastRow = range.getLastRow();
+ int firstCol = range.getFirstColumn();
+ int lastCol = range.getLastColumn();
+ for (int i = firstRow; i <= lastRow; i++) {
+ CellRangeAddress row = new CellRangeAddress(i, i, firstCol,
+ lastCol);
+ if (extent == BorderExtent.ALL || i > firstRow) {
+ drawTopBorder(row, borderType);
+ }
+ if (extent == BorderExtent.ALL || i < lastRow) {
+ drawBottomBorder(row, borderType);
+ }
}
- }
- break;
- default:
- throw new IllegalArgumentException(
- "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
}
}
@@ -375,28 +377,28 @@ public final class PropertyTemplate {
*
*/
private void drawVerticalBorders(CellRangeAddress range,
- BorderStyle borderType, BorderExtent extent) {
+ BorderStyle borderType, BorderExtent extent) {
switch (extent) {
- case ALL:
- case INSIDE:
- int firstRow = range.getFirstRow();
- int lastRow = range.getLastRow();
- int firstCol = range.getFirstColumn();
- int lastCol = range.getLastColumn();
- for (int i = firstCol; i <= lastCol; i++) {
- CellRangeAddress row = new CellRangeAddress(firstRow, lastRow,
- i, i);
- if (extent == BorderExtent.ALL || i > firstCol) {
- drawLeftBorder(row, borderType);
- }
- if (extent == BorderExtent.ALL || i < lastCol) {
- drawRightBorder(row, borderType);
+ case ALL:
+ case INSIDE:
+ int firstRow = range.getFirstRow();
+ int lastRow = range.getLastRow();
+ int firstCol = range.getFirstColumn();
+ int lastCol = range.getLastColumn();
+ for (int i = firstCol; i <= lastCol; i++) {
+ CellRangeAddress row = new CellRangeAddress(firstRow, lastRow,
+ i, i);
+ if (extent == BorderExtent.ALL || i > firstCol) {
+ drawLeftBorder(row, borderType);
+ }
+ if (extent == BorderExtent.ALL || i < lastCol) {
+ drawRightBorder(row, borderType);
+ }
}
- }
- break;
- default:
- throw new IllegalArgumentException(
- "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
}
}
@@ -407,11 +409,11 @@ public final class PropertyTemplate {
* @param range - {@link CellRangeAddress} range of cells to remove borders.
*/
private void removeBorders(CellRangeAddress range) {
- Set properties = new HashSet<>();
- properties.add(CellUtil.BORDER_TOP);
- properties.add(CellUtil.BORDER_BOTTOM);
- properties.add(CellUtil.BORDER_LEFT);
- properties.add(CellUtil.BORDER_RIGHT);
+ Set properties = new HashSet<>();
+ properties.add(CellPropertyType.BORDER_TOP);
+ properties.add(CellPropertyType.BORDER_BOTTOM);
+ properties.add(CellPropertyType.BORDER_LEFT);
+ properties.add(CellPropertyType.BORDER_RIGHT);
for (int row = range.getFirstRow(); row <= range.getLastRow(); row++) {
for (int col = range.getFirstColumn(); col <= range
.getLastColumn(); col++) {
@@ -431,16 +433,16 @@ public final class PropertyTemplate {
*/
public void applyBorders(Sheet sheet) {
Workbook wb = sheet.getWorkbook();
- for (Map.Entry> entry : _propertyTemplate
+ for (Map.Entry> entry : _propertyTemplate
.entrySet()) {
CellAddress cellAddress = entry.getKey();
if (cellAddress.getRow() < wb.getSpreadsheetVersion().getMaxRows()
&& cellAddress.getColumn() < wb.getSpreadsheetVersion()
- .getMaxColumns()) {
- Map properties = entry.getValue();
+ .getMaxColumns()) {
+ Map properties = entry.getValue();
Row row = CellUtil.getRow(cellAddress.getRow(), sheet);
Cell cell = CellUtil.getCell(row, cellAddress.getColumn());
- CellUtil.setCellStyleProperties(cell, properties);
+ CellUtil.setCellStylePropertiesEnum(cell, properties);
}
}
}
@@ -462,52 +464,52 @@ public final class PropertyTemplate {
* colors are set.
*/
public void drawBorderColors(CellRangeAddress range, short color,
- BorderExtent extent) {
+ BorderExtent extent) {
switch (extent) {
- case NONE:
- removeBorderColors(range);
- break;
- case ALL:
- drawHorizontalBorderColors(range, color, BorderExtent.ALL);
- drawVerticalBorderColors(range, color, BorderExtent.ALL);
- break;
- case INSIDE:
- drawHorizontalBorderColors(range, color, BorderExtent.INSIDE);
- drawVerticalBorderColors(range, color, BorderExtent.INSIDE);
- break;
- case OUTSIDE:
- drawOutsideBorderColors(range, color, BorderExtent.ALL);
- break;
- case TOP:
- drawTopBorderColor(range, color);
- break;
- case BOTTOM:
- drawBottomBorderColor(range, color);
- break;
- case LEFT:
- drawLeftBorderColor(range, color);
- break;
- case RIGHT:
- drawRightBorderColor(range, color);
- break;
- case HORIZONTAL:
- drawHorizontalBorderColors(range, color, BorderExtent.ALL);
- break;
- case INSIDE_HORIZONTAL:
- drawHorizontalBorderColors(range, color, BorderExtent.INSIDE);
- break;
- case OUTSIDE_HORIZONTAL:
- drawOutsideBorderColors(range, color, BorderExtent.HORIZONTAL);
- break;
- case VERTICAL:
- drawVerticalBorderColors(range, color, BorderExtent.ALL);
- break;
- case INSIDE_VERTICAL:
- drawVerticalBorderColors(range, color, BorderExtent.INSIDE);
- break;
- case OUTSIDE_VERTICAL:
- drawOutsideBorderColors(range, color, BorderExtent.VERTICAL);
- break;
+ case NONE:
+ removeBorderColors(range);
+ break;
+ case ALL:
+ drawHorizontalBorderColors(range, color, BorderExtent.ALL);
+ drawVerticalBorderColors(range, color, BorderExtent.ALL);
+ break;
+ case INSIDE:
+ drawHorizontalBorderColors(range, color, BorderExtent.INSIDE);
+ drawVerticalBorderColors(range, color, BorderExtent.INSIDE);
+ break;
+ case OUTSIDE:
+ drawOutsideBorderColors(range, color, BorderExtent.ALL);
+ break;
+ case TOP:
+ drawTopBorderColor(range, color);
+ break;
+ case BOTTOM:
+ drawBottomBorderColor(range, color);
+ break;
+ case LEFT:
+ drawLeftBorderColor(range, color);
+ break;
+ case RIGHT:
+ drawRightBorderColor(range, color);
+ break;
+ case HORIZONTAL:
+ drawHorizontalBorderColors(range, color, BorderExtent.ALL);
+ break;
+ case INSIDE_HORIZONTAL:
+ drawHorizontalBorderColors(range, color, BorderExtent.INSIDE);
+ break;
+ case OUTSIDE_HORIZONTAL:
+ drawOutsideBorderColors(range, color, BorderExtent.HORIZONTAL);
+ break;
+ case VERTICAL:
+ drawVerticalBorderColors(range, color, BorderExtent.ALL);
+ break;
+ case INSIDE_VERTICAL:
+ drawVerticalBorderColors(range, color, BorderExtent.INSIDE);
+ break;
+ case OUTSIDE_VERTICAL:
+ drawOutsideBorderColors(range, color, BorderExtent.VERTICAL);
+ break;
}
}
@@ -529,11 +531,11 @@ public final class PropertyTemplate {
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
if (getBorderStyle(row, i,
- CellUtil.BORDER_TOP) == BorderStyle.NONE) {
+ CellPropertyType.BORDER_TOP) == BorderStyle.NONE) {
drawTopBorder(new CellRangeAddress(row, row, i, i),
BorderStyle.THIN);
}
- addProperty(row, i, CellUtil.TOP_BORDER_COLOR, color);
+ addProperty(row, i, CellPropertyType.TOP_BORDER_COLOR, color);
}
}
@@ -555,11 +557,11 @@ public final class PropertyTemplate {
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
if (getBorderStyle(row, i,
- CellUtil.BORDER_BOTTOM) == BorderStyle.NONE) {
+ CellPropertyType.BORDER_BOTTOM) == BorderStyle.NONE) {
drawBottomBorder(new CellRangeAddress(row, row, i, i),
BorderStyle.THIN);
}
- addProperty(row, i, CellUtil.BOTTOM_BORDER_COLOR, color);
+ addProperty(row, i, CellPropertyType.BOTTOM_BORDER_COLOR, color);
}
}
@@ -581,11 +583,11 @@ public final class PropertyTemplate {
int col = range.getFirstColumn();
for (int i = firstRow; i <= lastRow; i++) {
if (getBorderStyle(i, col,
- CellUtil.BORDER_LEFT) == BorderStyle.NONE) {
+ CellPropertyType.BORDER_LEFT) == BorderStyle.NONE) {
drawLeftBorder(new CellRangeAddress(i, i, col, col),
BorderStyle.THIN);
}
- addProperty(i, col, CellUtil.LEFT_BORDER_COLOR, color);
+ addProperty(i, col, CellPropertyType.LEFT_BORDER_COLOR, color);
}
}
@@ -608,11 +610,11 @@ public final class PropertyTemplate {
int col = range.getLastColumn();
for (int i = firstRow; i <= lastRow; i++) {
if (getBorderStyle(i, col,
- CellUtil.BORDER_RIGHT) == BorderStyle.NONE) {
+ CellPropertyType.BORDER_RIGHT) == BorderStyle.NONE) {
drawRightBorder(new CellRangeAddress(i, i, col, col),
BorderStyle.THIN);
}
- addProperty(i, col, CellUtil.RIGHT_BORDER_COLOR, color);
+ addProperty(i, col, CellPropertyType.RIGHT_BORDER_COLOR, color);
}
}
@@ -637,23 +639,23 @@ public final class PropertyTemplate {
*
*/
private void drawOutsideBorderColors(CellRangeAddress range, short color,
- BorderExtent extent) {
+ BorderExtent extent) {
switch (extent) {
- case ALL:
- case HORIZONTAL:
- case VERTICAL:
- if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) {
- drawTopBorderColor(range, color);
- drawBottomBorderColor(range, color);
- }
- if (extent == BorderExtent.ALL || extent == BorderExtent.VERTICAL) {
- drawLeftBorderColor(range, color);
- drawRightBorderColor(range, color);
- }
- break;
- default:
- throw new IllegalArgumentException(
- "Unsupported PropertyTemplate.Extent, valid Extents are ALL, HORIZONTAL, and VERTICAL");
+ case ALL:
+ case HORIZONTAL:
+ case VERTICAL:
+ if (extent == BorderExtent.ALL || extent == BorderExtent.HORIZONTAL) {
+ drawTopBorderColor(range, color);
+ drawBottomBorderColor(range, color);
+ }
+ if (extent == BorderExtent.ALL || extent == BorderExtent.VERTICAL) {
+ drawLeftBorderColor(range, color);
+ drawRightBorderColor(range, color);
+ }
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported PropertyTemplate.Extent, valid Extents are ALL, HORIZONTAL, and VERTICAL");
}
}
@@ -677,28 +679,28 @@ public final class PropertyTemplate {
*
*/
private void drawHorizontalBorderColors(CellRangeAddress range, short color,
- BorderExtent extent) {
+ BorderExtent extent) {
switch (extent) {
- case ALL:
- case INSIDE:
- int firstRow = range.getFirstRow();
- int lastRow = range.getLastRow();
- int firstCol = range.getFirstColumn();
- int lastCol = range.getLastColumn();
- for (int i = firstRow; i <= lastRow; i++) {
- CellRangeAddress row = new CellRangeAddress(i, i, firstCol,
- lastCol);
- if (extent == BorderExtent.ALL || i > firstRow) {
- drawTopBorderColor(row, color);
+ case ALL:
+ case INSIDE:
+ int firstRow = range.getFirstRow();
+ int lastRow = range.getLastRow();
+ int firstCol = range.getFirstColumn();
+ int lastCol = range.getLastColumn();
+ for (int i = firstRow; i <= lastRow; i++) {
+ CellRangeAddress row = new CellRangeAddress(i, i, firstCol,
+ lastCol);
+ if (extent == BorderExtent.ALL || i > firstRow) {
+ drawTopBorderColor(row, color);
+ }
+ if (extent == BorderExtent.ALL || i < lastRow) {
+ drawBottomBorderColor(row, color);
+ }
}
- if (extent == BorderExtent.ALL || i < lastRow) {
- drawBottomBorderColor(row, color);
- }
- }
- break;
- default:
- throw new IllegalArgumentException(
- "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
}
}
@@ -722,28 +724,28 @@ public final class PropertyTemplate {
*
*/
private void drawVerticalBorderColors(CellRangeAddress range, short color,
- BorderExtent extent) {
+ BorderExtent extent) {
switch (extent) {
- case ALL:
- case INSIDE:
- int firstRow = range.getFirstRow();
- int lastRow = range.getLastRow();
- int firstCol = range.getFirstColumn();
- int lastCol = range.getLastColumn();
- for (int i = firstCol; i <= lastCol; i++) {
- CellRangeAddress row = new CellRangeAddress(firstRow, lastRow,
- i, i);
- if (extent == BorderExtent.ALL || i > firstCol) {
- drawLeftBorderColor(row, color);
+ case ALL:
+ case INSIDE:
+ int firstRow = range.getFirstRow();
+ int lastRow = range.getLastRow();
+ int firstCol = range.getFirstColumn();
+ int lastCol = range.getLastColumn();
+ for (int i = firstCol; i <= lastCol; i++) {
+ CellRangeAddress row = new CellRangeAddress(firstRow, lastRow,
+ i, i);
+ if (extent == BorderExtent.ALL || i > firstCol) {
+ drawLeftBorderColor(row, color);
+ }
+ if (extent == BorderExtent.ALL || i < lastCol) {
+ drawRightBorderColor(row, color);
+ }
}
- if (extent == BorderExtent.ALL || i < lastCol) {
- drawRightBorderColor(row, color);
- }
- }
- break;
- default:
- throw new IllegalArgumentException(
- "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
}
}
@@ -754,11 +756,11 @@ public final class PropertyTemplate {
* @param range - {@link CellRangeAddress} range of cells to remove borders.
*/
private void removeBorderColors(CellRangeAddress range) {
- Set properties = new HashSet<>();
- properties.add(CellUtil.TOP_BORDER_COLOR);
- properties.add(CellUtil.BOTTOM_BORDER_COLOR);
- properties.add(CellUtil.LEFT_BORDER_COLOR);
- properties.add(CellUtil.RIGHT_BORDER_COLOR);
+ Set properties = new HashSet<>();
+ properties.add(CellPropertyType.TOP_BORDER_COLOR);
+ properties.add(CellPropertyType.BOTTOM_BORDER_COLOR);
+ properties.add(CellPropertyType.LEFT_BORDER_COLOR);
+ properties.add(CellPropertyType.RIGHT_BORDER_COLOR);
for (int row = range.getFirstRow(); row <= range.getLastRow(); row++) {
for (int col = range.getFirstColumn(); col <= range
.getLastColumn(); col++) {
@@ -770,16 +772,16 @@ public final class PropertyTemplate {
/**
* Adds a property to this PropertyTemplate for a given cell
*/
- private void addProperty(int row, int col, String property, short value) {
+ private void addProperty(int row, int col, CellPropertyType property, short value) {
addProperty(row, col, property, Short.valueOf(value));
}
/**
* Adds a property to this PropertyTemplate for a given cell
*/
- private void addProperty(int row, int col, String property, Object value) {
+ private void addProperty(int row, int col, CellPropertyType property, Object value) {
CellAddress cell = new CellAddress(row, col);
- Map cellProperties = _propertyTemplate.get(cell);
+ Map cellProperties = _propertyTemplate.get(cell);
if (cellProperties == null) {
cellProperties = new HashMap<>();
}
@@ -791,9 +793,9 @@ public final class PropertyTemplate {
* Removes a set of properties from this PropertyTemplate for a
* given cell
*/
- private void removeProperties(int row, int col, Set properties) {
+ private void removeProperties(int row, int col, Set properties) {
CellAddress cell = new CellAddress(row, col);
- Map cellProperties = _propertyTemplate.get(cell);
+ Map cellProperties = _propertyTemplate.get(cell);
if (cellProperties != null) {
cellProperties.keySet().removeAll(properties);
if (cellProperties.isEmpty()) {
@@ -808,20 +810,20 @@ public final class PropertyTemplate {
* Retrieves the number of borders assigned to a cell
*/
public int getNumBorders(CellAddress cell) {
- Map cellProperties = _propertyTemplate.get(cell);
+ Map cellProperties = _propertyTemplate.get(cell);
if (cellProperties == null) {
return 0;
}
int count = 0;
- for (String property : cellProperties.keySet()) {
- if (property.equals(CellUtil.BORDER_TOP))
+ for (CellPropertyType property : cellProperties.keySet()) {
+ if (property.equals(CellPropertyType.BORDER_TOP))
count += 1;
- if (property.equals(CellUtil.BORDER_BOTTOM))
+ if (property.equals(CellPropertyType.BORDER_BOTTOM))
count += 1;
- if (property.equals(CellUtil.BORDER_LEFT))
+ if (property.equals(CellPropertyType.BORDER_LEFT))
count += 1;
- if (property.equals(CellUtil.BORDER_RIGHT))
+ if (property.equals(CellPropertyType.BORDER_RIGHT))
count += 1;
}
return count;
@@ -838,20 +840,20 @@ public final class PropertyTemplate {
* Retrieves the number of border colors assigned to a cell
*/
public int getNumBorderColors(CellAddress cell) {
- Map cellProperties = _propertyTemplate.get(cell);
+ Map cellProperties = _propertyTemplate.get(cell);
if (cellProperties == null) {
return 0;
}
int count = 0;
- for (String property : cellProperties.keySet()) {
- if (property.equals(CellUtil.TOP_BORDER_COLOR))
+ for (CellPropertyType property : cellProperties.keySet()) {
+ if (property.equals(CellPropertyType.TOP_BORDER_COLOR))
count += 1;
- if (property.equals(CellUtil.BOTTOM_BORDER_COLOR))
+ if (property.equals(CellPropertyType.BOTTOM_BORDER_COLOR))
count += 1;
- if (property.equals(CellUtil.LEFT_BORDER_COLOR))
+ if (property.equals(CellPropertyType.LEFT_BORDER_COLOR))
count += 1;
- if (property.equals(CellUtil.RIGHT_BORDER_COLOR))
+ if (property.equals(CellPropertyType.RIGHT_BORDER_COLOR))
count += 1;
}
return count;
@@ -867,9 +869,9 @@ public final class PropertyTemplate {
/**
* Retrieves the border style for a given cell
*/
- public BorderStyle getBorderStyle(CellAddress cell, String property) {
+ public BorderStyle getBorderStyle(CellAddress cell, CellPropertyType property) {
BorderStyle value = BorderStyle.NONE;
- Map cellProperties = _propertyTemplate.get(cell);
+ Map cellProperties = _propertyTemplate.get(cell);
if (cellProperties != null) {
Object obj = cellProperties.get(property);
if (obj instanceof BorderStyle) {
@@ -879,19 +881,39 @@ public final class PropertyTemplate {
return value;
}
+ /**
+ * Retrieves the border style for a given cell
+ *
+ * @deprecated See {@link #getBorderStyle(CellAddress, CellPropertyType)}
+ */
+ @Deprecated
+ public BorderStyle getBorderStyle(CellAddress cell, String propertyName) {
+ return getBorderStyle(cell, CellUtil.namePropertyMap.get(propertyName));
+ }
+
/**
* Retrieves the border style for a given cell
*/
- public BorderStyle getBorderStyle(int row, int col, String property) {
+ public BorderStyle getBorderStyle(int row, int col, CellPropertyType property) {
return getBorderStyle(new CellAddress(row, col), property);
}
/**
* Retrieves the border style for a given cell
+ *
+ * @deprecated See {@link #getBorderStyle(int, int, CellPropertyType)}
*/
- public short getTemplateProperty(CellAddress cell, String property) {
+ @Deprecated
+ public BorderStyle getBorderStyle(int row, int col, String propertyName) {
+ return getBorderStyle(new CellAddress(row, col), CellUtil.namePropertyMap.get(propertyName));
+ }
+
+ /**
+ * Retrieves the border style for a given cell
+ */
+ public short getTemplateProperty(CellAddress cell, CellPropertyType property) {
short value = 0;
- Map cellProperties = _propertyTemplate.get(cell);
+ Map cellProperties = _propertyTemplate.get(cell);
if (cellProperties != null) {
Object obj = cellProperties.get(property);
if (obj != null) {
@@ -901,13 +923,33 @@ public final class PropertyTemplate {
return value;
}
+ /**
+ * Retrieves the border style for a given cell
+ *
+ * @deprecated See {@link #getTemplateProperty(CellAddress, CellPropertyType)}
+ */
+ @Deprecated
+ public short getTemplateProperty(CellAddress cell, String propertyName) {
+ return getTemplateProperty(cell, CellUtil.namePropertyMap.get(propertyName));
+ }
+
/**
* Retrieves the border style for a given cell
*/
- public short getTemplateProperty(int row, int col, String property) {
+ public short getTemplateProperty(int row, int col, CellPropertyType property) {
return getTemplateProperty(new CellAddress(row, col), property);
}
+ /**
+ * Retrieves the border style for a given cell
+ *
+ * @deprecated See {@link #getTemplateProperty(int, int, CellPropertyType)}
+ */
+ @Deprecated
+ public short getTemplateProperty(int row, int col, String propertyName) {
+ return getTemplateProperty(new CellAddress(row, col), CellUtil.namePropertyMap.get(propertyName));
+ }
+
/**
* Converts a Short object to a short value or 0 if the object is not a
* Short
diff --git a/poi/src/main/java/org/apache/poi/ss/util/RegionUtil.java b/poi/src/main/java/org/apache/poi/ss/util/RegionUtil.java
index 7846d015a8..65a552d1ee 100644
--- a/poi/src/main/java/org/apache/poi/ss/util/RegionUtil.java
+++ b/poi/src/main/java/org/apache/poi/ss/util/RegionUtil.java
@@ -19,8 +19,10 @@ package org.apache.poi.ss.util;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellPropertyType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.util.Removal;
/**
* Various utility functions that make working with a region of cells easier.
@@ -36,30 +38,46 @@ public final class RegionUtil {
*/
private static final class CellPropertySetter {
- private final String _propertyName;
+ private final CellPropertyType property;
private final Object _propertyValue;
-
+ @Deprecated
public CellPropertySetter(String propertyName, int value) {
- _propertyName = propertyName;
- _propertyValue = Integer.valueOf(value);
+ this(CellUtil.namePropertyMap.get(propertyName), value);
}
+
+ @Deprecated
+ @Removal(version = "7.0.0")
public CellPropertySetter(String propertyName, BorderStyle value) {
- _propertyName = propertyName;
+ this(CellUtil.namePropertyMap.get(propertyName), value);
+ }
+
+ /**
+ * @param property The property to set
+ * @param value The value to set the property to
+ * @since POI 5.3.1
+ */
+ public CellPropertySetter(CellPropertyType property, int value) {
+ this.property = property;
+ _propertyValue = Integer.valueOf(value);
+ }
+
+ public CellPropertySetter(CellPropertyType property, BorderStyle value) {
+ this.property = property;
_propertyValue = value;
}
public void setProperty(Row row, int column) {
// create cell if it does not exist
Cell cell = CellUtil.getCell(row, column);
- CellUtil.setCellStyleProperty(cell, _propertyName, _propertyValue);
+ CellUtil.setCellStyleProperty(cell, property, _propertyValue);
}
}
/**
* Sets the left border style for a region of cells by manipulating the cell style of the individual
* cells on the left
- *
+ *
* @param border The new border
* @param region The region that should have the border
* @param sheet The sheet that the region is on.
@@ -70,7 +88,7 @@ public final class RegionUtil {
int rowEnd = region.getLastRow();
int column = region.getFirstColumn();
- CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_LEFT, border);
+ CellPropertySetter cps = new CellPropertySetter(CellPropertyType.BORDER_LEFT, border);
for (int i = rowStart; i <= rowEnd; i++) {
cps.setProperty(CellUtil.getRow(i, sheet), column);
}
@@ -79,7 +97,7 @@ public final class RegionUtil {
/**
* Sets the left border color for a region of cells by manipulating the cell style of the individual
* cells on the left
- *
+ *
* @param color The color of the border
* @param region The region that should have the border
* @param sheet The sheet that the region is on.
@@ -90,7 +108,7 @@ public final class RegionUtil {
int rowEnd = region.getLastRow();
int column = region.getFirstColumn();
- CellPropertySetter cps = new CellPropertySetter(CellUtil.LEFT_BORDER_COLOR, color);
+ CellPropertySetter cps = new CellPropertySetter(CellPropertyType.LEFT_BORDER_COLOR, color);
for (int i = rowStart; i <= rowEnd; i++) {
cps.setProperty(CellUtil.getRow(i, sheet), column);
}
@@ -99,7 +117,7 @@ public final class RegionUtil {
/**
* Sets the right border style for a region of cells by manipulating the cell style of the individual
* cells on the right
- *
+ *
* @param border The new border
* @param region The region that should have the border
* @param sheet The sheet that the region is on.
@@ -110,7 +128,7 @@ public final class RegionUtil {
int rowEnd = region.getLastRow();
int column = region.getLastColumn();
- CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_RIGHT, border);
+ CellPropertySetter cps = new CellPropertySetter(CellPropertyType.BORDER_RIGHT, border);
for (int i = rowStart; i <= rowEnd; i++) {
cps.setProperty(CellUtil.getRow(i, sheet), column);
}
@@ -119,7 +137,7 @@ public final class RegionUtil {
/**
* Sets the right border color for a region of cells by manipulating the cell style of the individual
* cells on the right
- *
+ *
* @param color The color of the border
* @param region The region that should have the border
* @param sheet The sheet that the region is on.
@@ -130,7 +148,7 @@ public final class RegionUtil {
int rowEnd = region.getLastRow();
int column = region.getLastColumn();
- CellPropertySetter cps = new CellPropertySetter(CellUtil.RIGHT_BORDER_COLOR, color);
+ CellPropertySetter cps = new CellPropertySetter(CellPropertyType.RIGHT_BORDER_COLOR, color);
for (int i = rowStart; i <= rowEnd; i++) {
cps.setProperty(CellUtil.getRow(i, sheet), column);
}
@@ -139,7 +157,7 @@ public final class RegionUtil {
/**
* Sets the bottom border style for a region of cells by manipulating the cell style of the individual
* cells on the bottom
- *
+ *
* @param border The new border
* @param region The region that should have the border
* @param sheet The sheet that the region is on.
@@ -149,7 +167,7 @@ public final class RegionUtil {
int colStart = region.getFirstColumn();
int colEnd = region.getLastColumn();
int rowIndex = region.getLastRow();
- CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_BOTTOM, border);
+ CellPropertySetter cps = new CellPropertySetter(CellPropertyType.BORDER_BOTTOM, border);
Row row = CellUtil.getRow(rowIndex, sheet);
for (int i = colStart; i <= colEnd; i++) {
cps.setProperty(row, i);
@@ -159,7 +177,7 @@ public final class RegionUtil {
/**
* Sets the bottom border color for a region of cells by manipulating the cell style of the individual
* cells on the bottom
- *
+ *
* @param color The color of the border
* @param region The region that should have the border
* @param sheet The sheet that the region is on.
@@ -169,7 +187,7 @@ public final class RegionUtil {
int colStart = region.getFirstColumn();
int colEnd = region.getLastColumn();
int rowIndex = region.getLastRow();
- CellPropertySetter cps = new CellPropertySetter(CellUtil.BOTTOM_BORDER_COLOR, color);
+ CellPropertySetter cps = new CellPropertySetter(CellPropertyType.BOTTOM_BORDER_COLOR, color);
Row row = CellUtil.getRow(rowIndex, sheet);
for (int i = colStart; i <= colEnd; i++) {
cps.setProperty(row, i);
@@ -179,7 +197,7 @@ public final class RegionUtil {
/**
* Sets the top border style for a region of cells by manipulating the cell style of the individual
* cells on the top
- *
+ *
* @param border The new border
* @param region The region that should have the border
* @param sheet The sheet that the region is on.
@@ -189,7 +207,7 @@ public final class RegionUtil {
int colStart = region.getFirstColumn();
int colEnd = region.getLastColumn();
int rowIndex = region.getFirstRow();
- CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_TOP, border);
+ CellPropertySetter cps = new CellPropertySetter(CellPropertyType.BORDER_TOP, border);
Row row = CellUtil.getRow(rowIndex, sheet);
for (int i = colStart; i <= colEnd; i++) {
cps.setProperty(row, i);
@@ -199,7 +217,7 @@ public final class RegionUtil {
/**
* Sets the top border color for a region of cells by manipulating the cell style of the individual
* cells on the top
- *
+ *
* @param color The color of the border
* @param region The region that should have the border
* @param sheet The sheet that the region is on.
@@ -209,7 +227,7 @@ public final class RegionUtil {
int colStart = region.getFirstColumn();
int colEnd = region.getLastColumn();
int rowIndex = region.getFirstRow();
- CellPropertySetter cps = new CellPropertySetter(CellUtil.TOP_BORDER_COLOR, color);
+ CellPropertySetter cps = new CellPropertySetter(CellPropertyType.TOP_BORDER_COLOR, color);
Row row = CellUtil.getRow(rowIndex, sheet);
for (int i = colStart; i <= colEnd; i++) {
cps.setProperty(row, i);
diff --git a/poi/src/test/java/org/apache/poi/ss/util/BaseTestCellUtil.java b/poi/src/test/java/org/apache/poi/ss/util/BaseTestCellUtil.java
index 98927502a3..9784e080b5 100644
--- a/poi/src/test/java/org/apache/poi/ss/util/BaseTestCellUtil.java
+++ b/poi/src/test/java/org/apache/poi/ss/util/BaseTestCellUtil.java
@@ -17,31 +17,21 @@
package org.apache.poi.ss.util;
+import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.ss.usermodel.*;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.poi.ss.ITestDataProvider;
-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.FillPatternType;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.VerticalAlignment;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.junit.jupiter.api.Test;
/**
* Tests Spreadsheet CellUtil
@@ -55,6 +45,27 @@ public abstract class BaseTestCellUtil {
_testDataProvider = testDataProvider;
}
+ @Test
+ void setCellStylePropertyByEnum() throws IOException {
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
+
+ // Add a border should create a new style
+ int styCnt1 = wb.getNumCellStyles();
+ CellUtil.setCellStyleProperty(c, CellPropertyType.BORDER_BOTTOM, BorderStyle.THIN);
+ int styCnt2 = wb.getNumCellStyles();
+ assertEquals(styCnt1 + 1, styCnt2);
+
+ // Add same border to another cell, should not create another style
+ c = r.createCell(1);
+ CellUtil.setCellStyleProperty(c, CellPropertyType.BORDER_BOTTOM, BorderStyle.THIN);
+ int styCnt3 = wb.getNumCellStyles();
+ assertEquals(styCnt2, styCnt3);
+ }
+ }
+
@Test
void setCellStyleProperty() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
@@ -76,6 +87,19 @@ public abstract class BaseTestCellUtil {
}
}
+ @Test
+ void setCellStylePropertyWithInvalidValueByEnum() throws IOException {
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
+
+ // An invalid BorderStyle constant
+ assertThrows(RuntimeException.class, () -> CellUtil.setCellStyleProperty(c, CellPropertyType.BORDER_BOTTOM, 42));
+ }
+ }
+
+
@Test
void setCellStylePropertyWithInvalidValue() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
@@ -105,6 +129,39 @@ public abstract class BaseTestCellUtil {
}
}
+ @Test()
+ void setCellStylePropertyBorderWithShortAndEnumByEnum() throws IOException {
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
+
+ // A valid BorderStyle constant, as a Short
+ CellUtil.setCellStyleProperty(c, CellPropertyType.BORDER_BOTTOM, BorderStyle.DASH_DOT.getCode());
+ assertEquals(BorderStyle.DASH_DOT, c.getCellStyle().getBorderBottom());
+
+ // A valid BorderStyle constant, as an Enum
+ CellUtil.setCellStyleProperty(c, CellPropertyType.BORDER_TOP, BorderStyle.MEDIUM_DASH_DOT);
+ assertEquals(BorderStyle.MEDIUM_DASH_DOT, c.getCellStyle().getBorderTop());
+ }
+ }
+
+ @Test()
+ void setCellStylePropertyWithShrinkToFitByEnum() throws IOException {
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
+
+ // Assert that the default shrinkToFit is false
+ assertFalse(c.getCellStyle().getShrinkToFit());
+
+ // Set shrinkToFit to true
+ CellUtil.setCellStyleProperty(c, CellPropertyType.SHRINK_TO_FIT, true);
+ assertTrue(c.getCellStyle().getShrinkToFit());
+ }
+ }
+
@Test()
void setCellStylePropertyWithShrinkToFit() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
@@ -121,6 +178,22 @@ public abstract class BaseTestCellUtil {
}
}
+ @Test()
+ void setCellStylePropertyWithQuotePrefixedByEnum() throws IOException {
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
+
+ // Assert that the default quotePrefixed is false
+ assertFalse(c.getCellStyle().getQuotePrefixed());
+
+ // Set quotePrefixed to true
+ CellUtil.setCellStyleProperty(c, CellPropertyType.QUOTE_PREFIXED, true);
+ assertTrue(c.getCellStyle().getQuotePrefixed());
+ }
+ }
+
@Test()
void setCellStylePropertyWithQuotePrefixed() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
@@ -143,6 +216,7 @@ public abstract class BaseTestCellUtil {
Sheet s = wb.createSheet();
Row r = s.createRow(0);
Cell c = r.createCell(0);
+ Cell c2 = r.createCell(1);
Font f = wb.createFont();
f.setBold(true);
@@ -195,12 +269,15 @@ public abstract class BaseTestCellUtil {
cs.setShrinkToFit(true);
cs.setQuotePrefixed(true);
c.setCellStyle(cs);
+ c2.setCellStyle(cs);
// Set BorderBottom from THIN to DOUBLE with setCellStyleProperty()
- CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, BorderStyle.DOUBLE);
+ CellUtil.setCellStyleProperty(c, CellPropertyType.BORDER_BOTTOM, BorderStyle.DOUBLE);
+ CellUtil.setCellStyleProperty(c2, CellUtil.BORDER_BOTTOM, BorderStyle.DOUBLE);
// Assert that only BorderBottom has been changed and no others.
assertEquals(BorderStyle.DOUBLE, c.getCellStyle().getBorderBottom());
+ assertEquals(BorderStyle.DOUBLE, c2.getCellStyle().getBorderBottom());
assertEquals(HorizontalAlignment.CENTER, c.getCellStyle().getAlignment());
assertEquals(BorderStyle.THIN, c.getCellStyle().getBorderLeft());
assertEquals(BorderStyle.THIN, c.getCellStyle().getBorderRight());
@@ -253,6 +330,34 @@ public abstract class BaseTestCellUtil {
}
}
+ @Test
+ void setCellStylePropertiesEnum() throws IOException {
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
+
+ // Add multiple border properties to cell should create a single new style
+ int styCnt1 = wb.getNumCellStyles();
+ Map props = new HashMap<>();
+ props.put(CellPropertyType.BORDER_TOP, BorderStyle.THIN);
+ props.put(CellPropertyType.BORDER_BOTTOM, BorderStyle.THIN);
+ props.put(CellPropertyType.BORDER_LEFT, BorderStyle.THIN);
+ props.put(CellPropertyType.BORDER_RIGHT, BorderStyle.THIN);
+ props.put(CellPropertyType.ALIGNMENT, HorizontalAlignment.CENTER.getCode()); // try it both with a Short (deprecated)
+ props.put(CellPropertyType.VERTICAL_ALIGNMENT, VerticalAlignment.CENTER); // and with an enum
+ CellUtil.setCellStylePropertiesEnum(c, props);
+ int styCnt2 = wb.getNumCellStyles();
+ assertEquals(styCnt1 + 1, styCnt2, "Only one additional style should have been created");
+
+ // Add same border another to same cell, should not create another style
+ c = r.createCell(1);
+ CellUtil.setCellStylePropertiesEnum(c, props);
+ int styCnt3 = wb.getNumCellStyles();
+ assertEquals(styCnt2, styCnt3, "No additional styles should have been created");
+ }
+ }
+
@Test
void getRow() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
@@ -443,7 +548,7 @@ public abstract class BaseTestCellUtil {
@Test
void setFontFromDifferentWorkbook() throws IOException {
try (Workbook wb1 = _testDataProvider.createWorkbook();
- Workbook wb2 = _testDataProvider.createWorkbook()) {
+ Workbook wb2 = _testDataProvider.createWorkbook()) {
Font font1 = wb1.createFont();
Font font2 = wb2.createFont();
// do something to make font1 and font2 different
@@ -462,6 +567,29 @@ public abstract class BaseTestCellUtil {
/**
* bug 55555
+ *
+ * @since POI 3.15 beta 3
+ */
+ @Test
+ protected void setFillForegroundColorBeforeFillBackgroundColorEnumByEnum() throws IOException {
+ try (Workbook wb1 = _testDataProvider.createWorkbook()) {
+ Cell A1 = wb1.createSheet().createRow(0).createCell(0);
+ Map properties = new HashMap<>();
+ properties.put(CellPropertyType.FILL_PATTERN, FillPatternType.BRICKS);
+ properties.put(CellPropertyType.FILL_FOREGROUND_COLOR, IndexedColors.BLUE.index);
+ properties.put(CellPropertyType.FILL_BACKGROUND_COLOR, IndexedColors.RED.index);
+
+ CellUtil.setCellStylePropertiesEnum(A1, properties);
+ CellStyle style = A1.getCellStyle();
+ assertEquals(FillPatternType.BRICKS, style.getFillPattern(), "fill pattern");
+ assertEquals(IndexedColors.BLUE, IndexedColors.fromInt(style.getFillForegroundColor()), "fill foreground color");
+ assertEquals(IndexedColors.RED, IndexedColors.fromInt(style.getFillBackgroundColor()), "fill background color");
+ }
+ }
+
+ /**
+ * bug 55555
+ *
* @since POI 3.15 beta 3
*/
@Test
@@ -483,6 +611,7 @@ public abstract class BaseTestCellUtil {
/**
* bug 63268
+ *
* @since POI 4.1.0
*/
@Test
diff --git a/poi/src/test/java/org/apache/poi/ss/util/TestPropertyTemplate.java b/poi/src/test/java/org/apache/poi/ss/util/TestPropertyTemplate.java
index bd57735706..eb226466d5 100644
--- a/poi/src/test/java/org/apache/poi/ss/util/TestPropertyTemplate.java
+++ b/poi/src/test/java/org/apache/poi/ss/util/TestPropertyTemplate.java
@@ -17,15 +17,11 @@
package org.apache.poi.ss.util;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotSame;
-
-import java.io.IOException;
-
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderExtent;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellPropertyType;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
@@ -33,6 +29,11 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.jupiter.api.Test;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+
/**
* Tests Spreadsheet PropertyTemplate
*
@@ -63,6 +64,24 @@ final class TestPropertyTemplate {
assertEquals(0, pt.getNumBorderColors(0, 0));
}
+ @Test
+ void getTemplatePropertiesByEnum() throws IOException {
+ CellRangeAddress a1 = new CellRangeAddress(0, 0, 0, 0);
+ PropertyTemplate pt = new PropertyTemplate();
+ pt.drawBorders(a1, BorderStyle.THIN, BorderExtent.TOP);
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(0, 0, CellPropertyType.BORDER_TOP));
+ pt.drawBorders(a1, BorderStyle.MEDIUM, BorderExtent.BOTTOM);
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(0, 0, CellPropertyType.BORDER_BOTTOM));
+ pt.drawBorderColors(a1, IndexedColors.RED.getIndex(), BorderExtent.TOP);
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(0, 0, CellPropertyType.TOP_BORDER_COLOR));
+ pt.drawBorderColors(a1, IndexedColors.BLUE.getIndex(), BorderExtent.BOTTOM);
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(0, 0, CellPropertyType.BOTTOM_BORDER_COLOR));
+ }
+
@Test
void getTemplateProperties() throws IOException {
CellRangeAddress a1 = new CellRangeAddress(0, 0, 0, 0);
@@ -82,7 +101,7 @@ final class TestPropertyTemplate {
}
@Test
- void drawBorders() throws IOException {
+ void drawBordersByEnum() throws IOException {
CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
PropertyTemplate pt = new PropertyTemplate();
pt.drawBorders(a1c3, BorderStyle.THIN,
@@ -91,13 +110,13 @@ final class TestPropertyTemplate {
for (int j = 0; j <= 2; j++) {
assertEquals(4, pt.getNumBorders(i, j));
assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
}
}
pt.drawBorders(a1c3, BorderStyle.MEDIUM,
@@ -109,300 +128,1019 @@ final class TestPropertyTemplate {
if (j == 0) {
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
} else if (j == 2) {
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
} else {
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
}
} else if (i == 2) {
if (j == 0) {
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
} else if (j == 2) {
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
} else {
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
+ }
+ } else {
+ if (j == 0) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_BOTTOM));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_RIGHT));
+ } else {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_RIGHT));
+ }
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.TOP);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.BOTTOM);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.LEFT);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.RIGHT);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.INSIDE_HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ } else if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ } else {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE_HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ } else if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.INSIDE_VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ } else {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE_VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ } else if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ }
+
+ @Test
+ void drawBorders() throws IOException {
+ CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
+ PropertyTemplate pt = new PropertyTemplate();
+ pt.drawBorders(a1c3, BorderStyle.THIN,
+ BorderExtent.ALL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ if (i == 0) {
+ if (j == 0) {
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ }
+ } else if (i == 2) {
+ if (j == 0) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ }
+ } else {
+ if (j == 0) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ }
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.TOP);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.BOTTOM);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.LEFT);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.RIGHT);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.INSIDE_HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ } else if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ } else {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE_HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ } else if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.INSIDE_VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ } else {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE_VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ } else if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ }
+
+ @Test
+ void drawBorderColorsByEnum() throws IOException {
+ CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
+ PropertyTemplate pt = new PropertyTemplate();
+ pt.drawBorderColors(a1c3, IndexedColors.RED.getIndex(),
+ BorderExtent.ALL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ assertEquals(4, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.RED.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ }
+ }
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
+ BorderExtent.OUTSIDE);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ assertEquals(4, pt.getNumBorderColors(i, j));
+ if (i == 0) {
+ if (j == 0) {
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ } else if (j == 2) {
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ } else {
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ }
+ } else if (i == 2) {
+ if (j == 0) {
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ } else if (j == 2) {
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ } else {
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
}
} else {
if (j == 0) {
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else if (j == 2) {
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else {
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
}
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.TOP);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.BOTTOM);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.LEFT);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.RIGHT);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.HORIZONTAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(2, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(2, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.INSIDE_HORIZONTAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
} else if (i == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
} else {
assertEquals(2, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(2, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.OUTSIDE_HORIZONTAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
} else if (i == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.VERTICAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(2, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(2, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.INSIDE_VERTICAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else if (j == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
} else {
assertEquals(2, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(2, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.OUTSIDE_VERTICAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
} else if (j == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
@@ -848,6 +1586,54 @@ final class TestPropertyTemplate {
}
}
+ @Test
+ void drawBordersWithColorsByEnum() throws IOException {
+ CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
+ PropertyTemplate pt = new PropertyTemplate();
+
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, IndexedColors.RED.getIndex(), BorderExtent.ALL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ assertEquals(4, pt.getNumBorderColors(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ assertEquals(IndexedColors.RED.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE, BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, IndexedColors.RED.getIndex(), BorderExtent.ALL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
+ assertEquals(BorderStyle.NONE,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.NONE,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ assertEquals(BorderStyle.NONE,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.NONE,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ }
+ }
+ }
+
@Test
void applyBorders() throws IOException {
CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
@@ -859,8 +1645,8 @@ final class TestPropertyTemplate {
pt.drawBorders(a1c3, BorderStyle.THIN, IndexedColors.RED.getIndex(), BorderExtent.ALL);
pt.applyBorders(sheet);
- for (Row row: sheet) {
- for (Cell cell: row) {
+ for (Row row : sheet) {
+ for (Cell cell : row) {
CellStyle cs = cell.getCellStyle();
assertEquals(BorderStyle.THIN, cs.getBorderTop());
assertEquals(IndexedColors.RED.getIndex(), cs.getTopBorderColor());
@@ -876,30 +1662,30 @@ final class TestPropertyTemplate {
pt.drawBorders(b2, BorderStyle.NONE, BorderExtent.ALL);
pt.applyBorders(sheet);
- for (Row row: sheet) {
- for (Cell cell: row) {
+ for (Row row : sheet) {
+ for (Cell cell : row) {
CellStyle cs = cell.getCellStyle();
if (cell.getColumnIndex() != 1 || row.getRowNum() == 0) {
- assertEquals(BorderStyle.THIN, cs.getBorderTop());
- assertEquals(IndexedColors.RED.getIndex(), cs.getTopBorderColor());
+ assertEquals(BorderStyle.THIN, cs.getBorderTop());
+ assertEquals(IndexedColors.RED.getIndex(), cs.getTopBorderColor());
} else {
assertEquals(BorderStyle.NONE, cs.getBorderTop());
}
if (cell.getColumnIndex() != 1 || row.getRowNum() == 2) {
- assertEquals(BorderStyle.THIN, cs.getBorderBottom());
- assertEquals(IndexedColors.RED.getIndex(), cs.getBottomBorderColor());
+ assertEquals(BorderStyle.THIN, cs.getBorderBottom());
+ assertEquals(IndexedColors.RED.getIndex(), cs.getBottomBorderColor());
} else {
assertEquals(BorderStyle.NONE, cs.getBorderBottom());
}
if (cell.getColumnIndex() == 0 || row.getRowNum() != 1) {
- assertEquals(BorderStyle.THIN, cs.getBorderLeft());
- assertEquals(IndexedColors.RED.getIndex(), cs.getLeftBorderColor());
+ assertEquals(BorderStyle.THIN, cs.getBorderLeft());
+ assertEquals(IndexedColors.RED.getIndex(), cs.getLeftBorderColor());
} else {
assertEquals(BorderStyle.NONE, cs.getBorderLeft());
}
if (cell.getColumnIndex() == 2 || row.getRowNum() != 1) {
- assertEquals(BorderStyle.THIN, cs.getBorderRight());
- assertEquals(IndexedColors.RED.getIndex(), cs.getRightBorderColor());
+ assertEquals(BorderStyle.THIN, cs.getBorderRight());
+ assertEquals(IndexedColors.RED.getIndex(), cs.getRightBorderColor());
} else {
assertEquals(BorderStyle.NONE, cs.getBorderRight());
}
@@ -923,7 +1709,7 @@ final class TestPropertyTemplate {
}
}
- CellRangeAddress b2 = new CellRangeAddress(1,1,1,1);
+ CellRangeAddress b2 = new CellRangeAddress(1, 1, 1, 1);
pt2.drawBorders(b2, BorderStyle.THIN, BorderExtent.ALL);
Workbook wb = new HSSFWorkbook();
--
2.39.5