import java.io.IOException;
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.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.PropertyTemplate;
+import org.apache.poi.ss.util.PropertyTemplate.Extent;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
// draw borders (three 3x3 grids)
PropertyTemplate pt = new PropertyTemplate();
+
// #1) these borders will all be medium in default color
- pt.drawBorders(new CellRangeAddress(1, 3, 1, 3),
- CellStyle.BORDER_MEDIUM, PropertyTemplate.Extent.ALL);
+ pt.drawBorders(new CellRangeAddress(1, 3, 1, 3), BorderStyle.MEDIUM, Extent.ALL);
+
// #2) these cells will have medium outside borders and thin inside borders
- pt.drawBorders(new CellRangeAddress(5, 7, 1, 3),
- CellStyle.BORDER_MEDIUM, PropertyTemplate.Extent.OUTSIDE);
- pt.drawBorders(new CellRangeAddress(5, 7, 1, 3), CellStyle.BORDER_THIN,
- PropertyTemplate.Extent.INSIDE);
+ pt.drawBorders(new CellRangeAddress(5, 7, 1, 3), BorderStyle.MEDIUM, Extent.OUTSIDE);
+ pt.drawBorders(new CellRangeAddress(5, 7, 1, 3), BorderStyle.THIN, Extent.INSIDE);
+
// #3) these cells will all be medium weight with different colors for the
// outside, inside horizontal, and inside vertical borders. The center
// cell will have no borders.
- pt.drawBorders(new CellRangeAddress(9, 11, 1, 3),
- CellStyle.BORDER_MEDIUM, IndexedColors.RED.getIndex(),
- PropertyTemplate.Extent.OUTSIDE);
- pt.drawBorders(new CellRangeAddress(9, 11, 1, 3),
- CellStyle.BORDER_MEDIUM, IndexedColors.BLUE.getIndex(),
- PropertyTemplate.Extent.INSIDE_VERTICAL);
- pt.drawBorders(new CellRangeAddress(9, 11, 1, 3),
- CellStyle.BORDER_MEDIUM, IndexedColors.GREEN.getIndex(),
- PropertyTemplate.Extent.INSIDE_HORIZONTAL);
- pt.drawBorders(new CellRangeAddress(10, 10, 2, 2),
- CellStyle.BORDER_NONE,
- PropertyTemplate.Extent.ALL);
+ pt.drawBorders(new CellRangeAddress(9, 11, 1, 3), BorderStyle.MEDIUM, IndexedColors.RED.getIndex(), Extent.OUTSIDE);
+ pt.drawBorders(new CellRangeAddress(9, 11, 1, 3), BorderStyle.MEDIUM, IndexedColors.BLUE.getIndex(), Extent.INSIDE_VERTICAL);
+ pt.drawBorders(new CellRangeAddress(9, 11, 1, 3), BorderStyle.MEDIUM, IndexedColors.GREEN.getIndex(), Extent.INSIDE_HORIZONTAL);
+ pt.drawBorders(new CellRangeAddress(10, 10, 2, 2), BorderStyle.NONE, Extent.ALL);
// apply borders to sheet
pt.applyBorders(sh1);
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.SpreadsheetVersion;
+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.IndexedColors;
* - {@link PropertyTemplate.Extent} of the borders to be
* applied.
*/
- public void drawBorders(CellRangeAddress range, short borderType,
- Extent extent) {
+ public void drawBorders(CellRangeAddress range, BorderStyle borderType, Extent extent) {
switch (extent) {
case NONE:
removeBorders(range);
* - {@link PropertyTemplate.Extent} of the borders to be
* applied.
*/
- public void drawBorders(CellRangeAddress range, short borderType,
+ public void drawBorders(CellRangeAddress range, BorderStyle borderType,
short color, Extent extent) {
drawBorders(range, borderType, extent);
- if (borderType != CellStyle.BORDER_NONE) {
+ if (borderType != BorderStyle.NONE) {
drawBorderColors(range, color, extent);
}
}
* - Type of border to draw. Use BORDER_XXX constants in
* {@link CellStyle}.
*/
- private void drawTopBorder(CellRangeAddress range, short borderType) {
+ private void drawTopBorder(CellRangeAddress range, BorderStyle borderType) {
int row = range.getFirstRow();
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
addProperty(row, i, CellUtil.BORDER_TOP, borderType);
- if (borderType == CellStyle.BORDER_NONE && row > 0) {
+ if (borderType == BorderStyle.NONE && row > 0) {
addProperty(row - 1, i, CellUtil.BORDER_BOTTOM, borderType);
}
}
* - Type of border to draw. Use BORDER_XXX constants in
* {@link CellStyle}.
*/
- private void drawBottomBorder(CellRangeAddress range, short borderType) {
+ private void drawBottomBorder(CellRangeAddress range, 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);
- if (borderType == CellStyle.BORDER_NONE
+ if (borderType == BorderStyle.NONE
&& row < SpreadsheetVersion.EXCEL2007.getMaxRows() - 1) {
addProperty(row + 1, i, CellUtil.BORDER_TOP, borderType);
}
* - Type of border to draw. Use BORDER_XXX constants in
* {@link CellStyle}.
*/
- private void drawLeftBorder(CellRangeAddress range, short borderType) {
+ private void drawLeftBorder(CellRangeAddress range, 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);
- if (borderType == CellStyle.BORDER_NONE && col > 0) {
+ if (borderType == BorderStyle.NONE && col > 0) {
addProperty(i, col - 1, CellUtil.BORDER_RIGHT, borderType);
}
}
* - Type of border to draw. Use BORDER_XXX constants in
* {@link CellStyle}.
*/
- private void drawRightBorder(CellRangeAddress range, short borderType) {
+ private void drawRightBorder(CellRangeAddress range, 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);
- if (borderType == CellStyle.BORDER_NONE
+ if (borderType == BorderStyle.NONE
&& col < SpreadsheetVersion.EXCEL2007.getMaxColumns() - 1) {
addProperty(i, col + 1, CellUtil.BORDER_LEFT, borderType);
}
* <li>CellBorder.Extent.VERTICAL</li>
* </ul>
*/
- private void drawOutsideBorders(CellRangeAddress range, short borderType,
- Extent extent) {
+ private void drawOutsideBorders(CellRangeAddress range, BorderStyle borderType, Extent extent) {
switch (extent) {
case ALL:
case HORIZONTAL:
* <li>CellBorder.Extent.INSIDE</li>
* </ul>
*/
- private void drawHorizontalBorders(CellRangeAddress range, short borderType,
- Extent extent) {
+ private void drawHorizontalBorders(CellRangeAddress range, BorderStyle borderType, Extent extent) {
switch (extent) {
case ALL:
case INSIDE:
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstRow; i <= lastRow; i++) {
- CellRangeAddress row = new CellRangeAddress(i, i, firstCol,
- lastCol);
+ CellRangeAddress row = new CellRangeAddress(i, i, firstCol, lastCol);
if (extent == Extent.ALL || i > firstRow) {
drawTopBorder(row, borderType);
}
* <li>CellBorder.Extent.INSIDE</li>
* </ul>
*/
- private void drawVerticalBorders(CellRangeAddress range, short borderType,
- Extent extent) {
+ private void drawVerticalBorders(CellRangeAddress range, BorderStyle borderType, Extent extent) {
switch (extent) {
case ALL:
case INSIDE:
* - {@link PropertyTemplate.Extent} of the borders for which
* colors are set.
*/
- public void drawBorderColors(CellRangeAddress range, short color,
- Extent extent) {
+ public void drawBorderColors(CellRangeAddress range, short color, Extent extent) {
switch (extent) {
case NONE:
removeBorderColors(range);
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
- if (getTemplateProperty(row, i, CellUtil.BORDER_TOP) == 0) {
- drawTopBorder(new CellRangeAddress(row, row, i, i),
- CellStyle.BORDER_THIN);
+ // if BORDER_TOP is not set on PropertyTemplate, make a thin border so that there's something to color
+ if (getTemplateProperty(row, i, CellUtil.BORDER_TOP) == null) {
+ drawTopBorder(new CellRangeAddress(row, row, i, i), BorderStyle.THIN);
}
addProperty(row, i, CellUtil.TOP_BORDER_COLOR, color);
}
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
- if (getTemplateProperty(row, i, CellUtil.BORDER_BOTTOM) == 0) {
- drawBottomBorder(new CellRangeAddress(row, row, i, i),
- CellStyle.BORDER_THIN);
+ // if BORDER_BOTTOM is not set on PropertyTemplate, make a thin border so that there's something to color
+ if (getTemplateProperty(row, i, CellUtil.BORDER_BOTTOM) == null) {
+ drawBottomBorder(new CellRangeAddress(row, row, i, i), BorderStyle.THIN);
}
addProperty(row, i, CellUtil.BOTTOM_BORDER_COLOR, color);
}
int lastRow = range.getLastRow();
int col = range.getFirstColumn();
for (int i = firstRow; i <= lastRow; i++) {
- if (getTemplateProperty(i, col, CellUtil.BORDER_LEFT) == 0) {
- drawLeftBorder(new CellRangeAddress(i, i, col, col),
- CellStyle.BORDER_THIN);
+ // if BORDER_LEFT is not set on PropertyTemplate, make a thin border so that there's something to color
+ if (getTemplateProperty(i, col, CellUtil.BORDER_LEFT) == null) {
+ drawLeftBorder(new CellRangeAddress(i, i, col, col), BorderStyle.THIN);
}
addProperty(i, col, CellUtil.LEFT_BORDER_COLOR, color);
}
int lastRow = range.getLastRow();
int col = range.getLastColumn();
for (int i = firstRow; i <= lastRow; i++) {
- if (getTemplateProperty(i, col, CellUtil.BORDER_RIGHT) == 0) {
- drawRightBorder(new CellRangeAddress(i, i, col, col),
- CellStyle.BORDER_THIN);
+ // if BORDER_RIGHT is not set on PropertyTemplate, make a thin border so that there's something to color
+ if (getTemplateProperty(i, col, CellUtil.BORDER_RIGHT) == null) {
+ drawRightBorder(new CellRangeAddress(i, i, col, col), BorderStyle.THIN);
}
addProperty(i, col, CellUtil.RIGHT_BORDER_COLOR, color);
}
* <li>CellBorder.Extent.VERTICAL</li>
* </ul>
*/
- private void drawOutsideBorderColors(CellRangeAddress range, short color,
- Extent extent) {
+ private void drawOutsideBorderColors(CellRangeAddress range, short color, Extent extent) {
switch (extent) {
case ALL:
case HORIZONTAL:
* <li>CellBorder.Extent.INSIDE</li>
* </ul>
*/
- private void drawHorizontalBorderColors(CellRangeAddress range, short color,
- Extent extent) {
+ private void drawHorizontalBorderColors(CellRangeAddress range, short color, Extent extent) {
switch (extent) {
case ALL:
case INSIDE:
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstRow; i <= lastRow; i++) {
- CellRangeAddress row = new CellRangeAddress(i, i, firstCol,
- lastCol);
+ CellRangeAddress row = new CellRangeAddress(i, i, firstCol, lastCol);
if (extent == Extent.ALL || i > firstRow) {
drawTopBorderColor(row, color);
}
* <li>CellBorder.Extent.INSIDE</li>
* </ul>
*/
- private void drawVerticalBorderColors(CellRangeAddress range, short color,
- Extent extent) {
+ private void drawVerticalBorderColors(CellRangeAddress range, short color, Extent extent) {
switch (extent) {
case ALL:
case INSIDE:
* @param property
* @param value
*/
- private void addProperty(int row, int col, String property, short value) {
+ private void addProperty(int row, int col, String property, Object value) {
CellAddress cell = new CellAddress(row, col);
Map<String, Object> cellProperties = _propertyTemplate.get(cell);
if (cellProperties == null) {
cellProperties = new HashMap<String, Object>();
}
- cellProperties.put(property, Short.valueOf(value));
+ cellProperties.put(property, value);
_propertyTemplate.put(cell, cellProperties);
}
}
/**
- * Retrieves the number of borders assigned to a cell
+ * Retrieves the number of borders assigned to a cell (a value between 0 and 4
*
* @param cell
*/
}
int count = 0;
- for (String property : cellProperties.keySet()) {
- if (property.equals(CellUtil.BORDER_TOP))
- count += 1;
- if (property.equals(CellUtil.BORDER_BOTTOM))
- count += 1;
- if (property.equals(CellUtil.BORDER_LEFT))
- count += 1;
- if (property.equals(CellUtil.BORDER_RIGHT))
- count += 1;
- }
+ if (cellProperties.containsKey(CellUtil.BORDER_TOP)) count++;
+ if (cellProperties.containsKey(CellUtil.BORDER_LEFT)) count++;
+ if (cellProperties.containsKey(CellUtil.BORDER_RIGHT)) count++;
+ if (cellProperties.containsKey(CellUtil.BORDER_BOTTOM)) count++;
return count;
}
}
int count = 0;
- for (String property : cellProperties.keySet()) {
- if (property.equals(CellUtil.TOP_BORDER_COLOR))
- count += 1;
- if (property.equals(CellUtil.BOTTOM_BORDER_COLOR))
- count += 1;
- if (property.equals(CellUtil.LEFT_BORDER_COLOR))
- count += 1;
- if (property.equals(CellUtil.RIGHT_BORDER_COLOR))
- count += 1;
- }
+ if (cellProperties.containsKey(CellUtil.TOP_BORDER_COLOR)) count++;
+ if (cellProperties.containsKey(CellUtil.LEFT_BORDER_COLOR)) count++;
+ if (cellProperties.containsKey(CellUtil.RIGHT_BORDER_COLOR)) count++;
+ if (cellProperties.containsKey(CellUtil.BOTTOM_BORDER_COLOR)) count++;
return count;
}
* @param cell
* @param property
*/
- public short getTemplateProperty(CellAddress cell, String property) {
- short value = 0;
+ public Object getTemplateProperty(CellAddress cell, String property) {
Map<String, Object> cellProperties = _propertyTemplate.get(cell);
if (cellProperties != null) {
- Object obj = cellProperties.get(property);
- if (obj != null) {
- value = getShort(obj);
- }
+ return cellProperties.get(property);
}
- return value;
+ return null;
}
/**
* @param col
* @param property
*/
- public short getTemplateProperty(int row, int col, String property) {
+ public Object getTemplateProperty(int row, int col, String property) {
return getTemplateProperty(new CellAddress(row, col), property);
}
-
- /**
- * Converts a Short object to a short value or 0 if the object is not a
- * Short
- *
- * @param value
- * @return
- */
- private static short getShort(Object value) {
- if (value instanceof Short) {
- return ((Short) value).shortValue();
- }
- return 0;
- }
}
CellRangeAddress a1 = new CellRangeAddress(0, 0, 0, 0);
PropertyTemplate pt = new PropertyTemplate();
- pt.drawBorders(a1, CellStyle.BORDER_THIN, Extent.TOP);
+ pt.drawBorders(a1, BorderStyle.THIN, Extent.TOP);
assertEquals(1, pt.getNumBorders(0, 0));
- pt.drawBorders(a1, CellStyle.BORDER_MEDIUM, Extent.BOTTOM);
+ pt.drawBorders(a1, BorderStyle.MEDIUM, Extent.BOTTOM);
assertEquals(2, pt.getNumBorders(0, 0));
- pt.drawBorders(a1, CellStyle.BORDER_MEDIUM, Extent.NONE);
+ pt.drawBorders(a1, BorderStyle.MEDIUM, Extent.NONE);
assertEquals(0, pt.getNumBorders(0, 0));
}
CellRangeAddress a1 = new CellRangeAddress(0, 0, 0, 0);
PropertyTemplate pt = new PropertyTemplate();
- pt.drawBorders(a1, CellStyle.BORDER_THIN, Extent.TOP);
+ pt.drawBorders(a1, BorderStyle.THIN, Extent.TOP);
assertThin(pt.getTemplateProperty(0, 0, CellUtil.BORDER_TOP));
- pt.drawBorders(a1, CellStyle.BORDER_MEDIUM, Extent.BOTTOM);
+ pt.drawBorders(a1, BorderStyle.MEDIUM, Extent.BOTTOM);
assertMedium(pt.getTemplateProperty(0, 0, CellUtil.BORDER_BOTTOM));
pt.drawBorderColors(a1, IndexedColors.RED.getIndex(), Extent.TOP);
CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
PropertyTemplate pt = new PropertyTemplate();
- pt.drawBorders(a1c3, CellStyle.BORDER_THIN, Extent.ALL);
+ pt.drawBorders(a1c3, BorderStyle.THIN, Extent.ALL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(4, pt.getNumBorders(i, j));
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.OUTSIDE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.OUTSIDE);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(4, pt.getNumBorders(i, j));
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(0, pt.getNumBorders(i, j));
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.TOP);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.TOP);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 0) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.BOTTOM);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.BOTTOM);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 2) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.LEFT);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.LEFT);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 0) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.RIGHT);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.RIGHT);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 2) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.HORIZONTAL);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.HORIZONTAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(2, pt.getNumBorders(i, j));
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.INSIDE_HORIZONTAL);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.INSIDE_HORIZONTAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 0) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.OUTSIDE_HORIZONTAL);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.OUTSIDE_HORIZONTAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 0) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.VERTICAL);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.VERTICAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(2, pt.getNumBorders(i, j));
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.INSIDE_VERTICAL);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.INSIDE_VERTICAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 0) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, Extent.OUTSIDE_VERTICAL);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, Extent.OUTSIDE_VERTICAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 0) {
pt.drawBorderColors(a1c3, IndexedColors.RED.getIndex(), Extent.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));
+ CellAddress addr = new CellAddress(i, j);
+ String msg = addr.formatAsString();
+ assertEquals(msg, 4, pt.getNumBorders(i, j));
+ assertEquals(msg, 4, pt.getNumBorderColors(i, j));
assertRed(pt.getTemplateProperty(i, j, CellUtil.TOP_BORDER_COLOR));
assertRed(pt.getTemplateProperty(i, j, CellUtil.BOTTOM_BORDER_COLOR));
assertRed(pt.getTemplateProperty(i, j, CellUtil.LEFT_BORDER_COLOR));
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(), Extent.BOTTOM);
for (int i = 0; i <= 2; i++) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(), Extent.LEFT);
for (int i = 0; i <= 2; i++) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(), Extent.RIGHT);
for (int i = 0; i <= 2; i++) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(), Extent.HORIZONTAL);
for (int i = 0; i <= 2; i++) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(), Extent.INSIDE_HORIZONTAL);
for (int i = 0; i <= 2; i++) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(), Extent.OUTSIDE_HORIZONTAL);
for (int i = 0; i <= 2; i++) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(), Extent.VERTICAL);
for (int i = 0; i <= 2; i++) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(), Extent.INSIDE_VERTICAL);
for (int i = 0; i <= 2; i++) {
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(), Extent.NONE);
pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(), Extent.OUTSIDE_VERTICAL);
for (int i = 0; i <= 2; i++) {
CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
PropertyTemplate pt = new PropertyTemplate();
- pt.drawBorders(a1c3, CellStyle.BORDER_MEDIUM, IndexedColors.RED.getIndex(), Extent.ALL);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM, IndexedColors.RED.getIndex(), Extent.ALL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(4, pt.getNumBorders(i, j));
}
}
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, Extent.NONE);
- pt.drawBorders(a1c3, CellStyle.BORDER_NONE, IndexedColors.RED.getIndex(), Extent.ALL);
+ pt.drawBorders(a1c3, BorderStyle.NONE, Extent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.NONE, IndexedColors.RED.getIndex(), Extent.ALL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(4, pt.getNumBorders(i, j));
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
- pt.drawBorders(a1c3, CellStyle.BORDER_THIN, IndexedColors.RED.getIndex(), Extent.ALL);
+ pt.drawBorders(a1c3, BorderStyle.THIN, IndexedColors.RED.getIndex(), Extent.ALL);
pt.applyBorders(sheet);
for (Row row: sheet) {
}
}
- pt.drawBorders(b2, CellStyle.BORDER_NONE, Extent.ALL);
+ pt.drawBorders(b2, BorderStyle.NONE, Extent.ALL);
pt.applyBorders(sheet);
for (Row row: sheet) {
// helper functions to make sure template properties were set correctly
//////// Border Styles ///////////
- private static void assertNone(short actual) {
- assertNone(BorderStyle.valueOf(actual));
+ private static void assertNone(Object actual) {
+ assertNone((BorderStyle) actual);
}
private static void assertNone(BorderStyle actual) {
assertEquals(BorderStyle.NONE, actual);
}
- private static void assertThin(short actual) {
- assertThin(BorderStyle.valueOf(actual));
+ private static void assertThin(Object actual) {
+ assertThin((BorderStyle) actual);
}
private static void assertThin(BorderStyle actual) {
assertEquals(BorderStyle.THIN, actual);
}
- private static void assertMedium(short actual) {
- assertMedium(BorderStyle.valueOf(actual));
+ private static void assertMedium(Object actual) {
+ assertMedium((BorderStyle) actual);
}
private static void assertMedium(BorderStyle actual) {
assertEquals(BorderStyle.MEDIUM, actual);
}
- //////// Border Colors ///////////
- private static void assertRed(short actualIndexedColor) {
- IndexedColors actualColor = IndexedColors.fromInt(actualIndexedColor);
- assertEquals(IndexedColors.RED, actualColor);
+ //////// Border Colors (use IndexedColor codes, for now ///////////
+ private static void assertRed(Object actual) {
+ IndexedColors actualColor = IndexedColors.fromInt((Short) actual);
+ assertRed(actualColor);
+ }
+ private static void assertRed(IndexedColors actual) {
+ assertEquals(IndexedColors.RED, actual);
+ }
+
+ private static void assertBlue(Object actual) {
+ IndexedColors actualColor = IndexedColors.fromInt((Short) actual);
+ assertBlue(actualColor);
}
- private static void assertBlue(short actualIndexedColor) {
- IndexedColors actualColor = IndexedColors.fromInt(actualIndexedColor);
- assertEquals(IndexedColors.BLUE, actualColor);
+ private static void assertBlue(IndexedColors actual) {
+ assertEquals(IndexedColors.BLUE, actual);
}
}