mirror of https://github.com/apache/poi.git
[github-682] Add CellPropertyType and CellPropertyCategory enums. Thanks to Danila Avdeyenko. This closes #682
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1920230 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
41453f3916
commit
abf153d6a4
|
@ -572,7 +572,7 @@ public class SXSSFCell extends CellBase {
|
|||
* the Workbook.</p>
|
||||
*
|
||||
* <p>To change the style of a cell without affecting other cells that use the same style,
|
||||
* use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, Map)}</p>
|
||||
* use {@link org.apache.poi.ss.util.CellUtil#setCellStylePropertiesEnum(Cell, Map)}</p>
|
||||
*
|
||||
* @param style reference contained in the workbook.
|
||||
* If the value is null then the style information is removed causing the cell to used the default workbook style.
|
||||
|
|
|
@ -606,7 +606,7 @@ public final class XSSFCell extends CellBase {
|
|||
* the XSSFWorkbook.</p>
|
||||
*
|
||||
* <p>To change the style of a cell without affecting other cells that use the same style,
|
||||
* use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, java.util.Map)}</p>
|
||||
* use {@link org.apache.poi.ss.util.CellUtil#setCellStylePropertiesEnum(Cell, java.util.Map)}</p>
|
||||
*
|
||||
* @param style reference contained in the workbook.
|
||||
* If the value is null then the style information is removed causing the cell to use the default workbook style.
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.poi.ss.tests.util;
|
|||
import org.apache.commons.codec.DecoderException;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellPropertyType;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
|
@ -32,19 +33,38 @@ import org.apache.poi.xssf.usermodel.XSSFColor;
|
|||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
class TestXSSFCellUtil extends BaseTestCellUtil {
|
||||
public TestXSSFCellUtil() {
|
||||
super(XSSFITestDataProvider.instance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetForegroundColorCellStylePropertyByEnum() throws IOException, DecoderException {
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
|
||||
final Sheet sheet = workbook.createSheet("Sheet");
|
||||
final Row row = sheet.createRow(0);
|
||||
final Cell cell = row.createCell(0);
|
||||
final XSSFColor color = new XSSFColor(Hex.decodeHex("AAAAAA"));
|
||||
|
||||
assertNull(cell.getCellStyle().getFillForegroundColorColor());
|
||||
|
||||
CellUtil.setCellStyleProperty(
|
||||
cell, CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, color);
|
||||
|
||||
assertEquals(color, cell.getCellStyle().getFillForegroundColorColor());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetForegroundColorCellStyleProperty() throws IOException, DecoderException {
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
|
@ -64,8 +84,32 @@ class TestXSSFCellUtil extends BaseTestCellUtil {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSetForegroundColorCellStylePropertyToNull() throws IOException, DecoderException {
|
||||
public void testSetForegroundColorCellStylePropertyToNullByEnum() throws IOException, DecoderException {
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
|
||||
final Sheet sheet = workbook.createSheet("Sheet");
|
||||
final Row row = sheet.createRow(0);
|
||||
final Cell cell = row.createCell(0);
|
||||
final XSSFColor color = new XSSFColor(Hex.decodeHex("AAAAAA"));
|
||||
|
||||
assertNull(cell.getCellStyle().getFillForegroundColorColor());
|
||||
|
||||
CellUtil.setCellStyleProperty(
|
||||
cell, CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, color);
|
||||
|
||||
assertEquals(color, cell.getCellStyle().getFillForegroundColorColor());
|
||||
|
||||
CellUtil.setCellStyleProperty(
|
||||
cell, CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, null);
|
||||
|
||||
assertNotEquals(color, cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertNull(cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertEquals(IndexedColors.AUTOMATIC.getIndex(), cell.getCellStyle().getFillForegroundColor());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetForegroundColorCellStylePropertyToNull() throws IOException, DecoderException {
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
|
||||
final Sheet sheet = workbook.createSheet("Sheet");
|
||||
|
@ -89,6 +133,41 @@ class TestXSSFCellUtil extends BaseTestCellUtil {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetForegroundColorCellStylePropertiesToNullByEnum() throws IOException, DecoderException {
|
||||
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
|
||||
final Sheet sheet = workbook.createSheet("Sheet");
|
||||
final Row row = sheet.createRow(0);
|
||||
final Cell cell = row.createCell(0);
|
||||
final XSSFColor color = new XSSFColor(Hex.decodeHex("FF0000"));
|
||||
|
||||
{
|
||||
final Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
|
||||
|
||||
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, color);
|
||||
properties.put(CellPropertyType.FILL_PATTERN, FillPatternType.SOLID_FOREGROUND);
|
||||
|
||||
CellUtil.setCellStylePropertiesEnum(cell, properties);
|
||||
}
|
||||
assertEquals(color, cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertEquals(FillPatternType.SOLID_FOREGROUND, cell.getCellStyle().getFillPattern());
|
||||
|
||||
{
|
||||
final Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
|
||||
|
||||
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, null);
|
||||
properties.put(CellPropertyType.FILL_PATTERN, FillPatternType.NO_FILL);
|
||||
|
||||
CellUtil.setCellStylePropertiesEnum(cell, properties);
|
||||
}
|
||||
assertNull(cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertEquals(IndexedColors.AUTOMATIC.getIndex(), cell.getCellStyle().getFillForegroundColor());
|
||||
assertEquals(FillPatternType.NO_FILL, cell.getCellStyle().getFillPattern());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetForegroundColorCellStylePropertiesToNull() throws IOException, DecoderException {
|
||||
|
||||
|
@ -124,9 +203,49 @@ class TestXSSFCellUtil extends BaseTestCellUtil {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBug66052WithWorkaroundByEnum() throws IOException, DecoderException {
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
|
||||
final Sheet sheet = workbook.createSheet("Sheet");
|
||||
final Row row = sheet.createRow(0);
|
||||
final Cell cell = row.createCell(0);
|
||||
final XSSFColor color = new XSSFColor(Hex.decodeHex("FFAAAA"));
|
||||
|
||||
assertNull(cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertNull(cell.getCellStyle().getFillBackgroundColorColor());
|
||||
|
||||
{
|
||||
Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
|
||||
|
||||
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, color);
|
||||
properties.put(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR, null); // WORKAROUND
|
||||
properties.put(CellPropertyType.FILL_PATTERN, FillPatternType.SOLID_FOREGROUND);
|
||||
|
||||
CellUtil.setCellStylePropertiesEnum(cell, properties);
|
||||
}
|
||||
|
||||
assertNotNull(cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertNull(cell.getCellStyle().getFillBackgroundColorColor());
|
||||
|
||||
{
|
||||
Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
|
||||
|
||||
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, null);
|
||||
properties.put(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR, null); // WORKAROUND
|
||||
properties.put(CellPropertyType.FILL_PATTERN, FillPatternType.NO_FILL);
|
||||
|
||||
CellUtil.setCellStylePropertiesEnum(cell, properties);
|
||||
}
|
||||
|
||||
assertNull(cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertNull(cell.getCellStyle().getFillBackgroundColorColor());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug66052WithWorkaround() throws IOException, DecoderException {
|
||||
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
|
||||
final Sheet sheet = workbook.createSheet("Sheet");
|
||||
|
@ -165,6 +284,47 @@ class TestXSSFCellUtil extends BaseTestCellUtil {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug66052WithoutWorkaroundByEnum() throws IOException, DecoderException {
|
||||
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
|
||||
final Sheet sheet = workbook.createSheet("Sheet");
|
||||
final Row row = sheet.createRow(0);
|
||||
final Cell cell = row.createCell(0);
|
||||
final XSSFColor color = new XSSFColor(Hex.decodeHex("FFAAAA"));
|
||||
|
||||
assertNull(cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertNull(cell.getCellStyle().getFillBackgroundColorColor());
|
||||
|
||||
{
|
||||
Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
|
||||
|
||||
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, color);
|
||||
properties.put(CellPropertyType.FILL_PATTERN, FillPatternType.SOLID_FOREGROUND);
|
||||
|
||||
CellUtil.setCellStylePropertiesEnum(cell, properties);
|
||||
}
|
||||
|
||||
assertEquals(color, cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertEquals(IndexedColors.AUTOMATIC.getIndex(),
|
||||
((XSSFColor) cell.getCellStyle().getFillBackgroundColorColor()).getIndex());
|
||||
|
||||
{
|
||||
Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
|
||||
|
||||
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, null);
|
||||
properties.put(CellPropertyType.FILL_PATTERN, FillPatternType.NO_FILL);
|
||||
|
||||
CellUtil.setCellStylePropertiesEnum(cell, properties);
|
||||
}
|
||||
|
||||
assertNull(cell.getCellStyle().getFillForegroundColorColor());
|
||||
assertEquals(IndexedColors.AUTOMATIC.getIndex(),
|
||||
((XSSFColor) cell.getCellStyle().getFillBackgroundColorColor()).getIndex());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug66052WithoutWorkaround() throws IOException, DecoderException {
|
||||
|
||||
|
@ -205,4 +365,4 @@ class TestXSSFCellUtil extends BaseTestCellUtil {
|
|||
((XSSFColor) cell.getCellStyle().getFillBackgroundColorColor()).getIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -946,7 +946,7 @@ public class HSSFCell extends CellBase {
|
|||
* the HSSFWorkbook.</p>
|
||||
*
|
||||
* <p>To change the style of a cell without affecting other cells that use the same style,
|
||||
* use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(org.apache.poi.ss.usermodel.Cell, java.util.Map)}</p>
|
||||
* use {@link org.apache.poi.ss.util.CellUtil#setCellStylePropertiesEnum(org.apache.poi.ss.usermodel.Cell, java.util.Map)}</p>
|
||||
*
|
||||
* @param style reference contained in the workbook
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createCellStyle()
|
||||
|
|
|
@ -369,7 +369,7 @@ public interface Cell {
|
|||
* the Workbook.</p>
|
||||
*
|
||||
* <p>To change the style of a cell without affecting other cells that use the same style,
|
||||
* use {@link org.apache.poi.ss.util.CellUtil#setCellStyleProperties(Cell, Map)}</p>
|
||||
* use {@link org.apache.poi.ss.util.CellUtil#setCellStylePropertiesEnum(Cell, Map)}</p>
|
||||
*
|
||||
* @param style reference contained in the workbook.
|
||||
* If the value is null then the style information is removed causing the cell to used the default workbook style.
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
/**
|
||||
* The CellPropertyCategory enum represents the different categories of cell properties.
|
||||
* Each category is used to classify and organize the cell properties based on their characteristics.
|
||||
*
|
||||
* @since POI 5.3.1
|
||||
*/
|
||||
public enum CellPropertyCategory {
|
||||
|
||||
SHORT,
|
||||
COLOR,
|
||||
INT,
|
||||
BOOL,
|
||||
BORDER_TYPE,
|
||||
OTHER
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
/**
|
||||
* The CellPropertyType enum represents the different types of cell properties that can be applied to a cell.
|
||||
* Each type is associated with a specific category {@link CellPropertyCategory}, which classifies and organizes
|
||||
* the properties based on their characteristics.
|
||||
*
|
||||
* @since POI 5.3.1
|
||||
*/
|
||||
public enum CellPropertyType {
|
||||
|
||||
BORDER_BOTTOM(CellPropertyCategory.BORDER_TYPE),
|
||||
BORDER_LEFT(CellPropertyCategory.BORDER_TYPE),
|
||||
BORDER_RIGHT(CellPropertyCategory.BORDER_TYPE),
|
||||
BORDER_TOP(CellPropertyCategory.BORDER_TYPE),
|
||||
|
||||
BOTTOM_BORDER_COLOR(CellPropertyCategory.SHORT),
|
||||
LEFT_BORDER_COLOR(CellPropertyCategory.SHORT),
|
||||
RIGHT_BORDER_COLOR(CellPropertyCategory.SHORT),
|
||||
TOP_BORDER_COLOR(CellPropertyCategory.SHORT),
|
||||
DATA_FORMAT(CellPropertyCategory.SHORT),
|
||||
FILL_BACKGROUND_COLOR(CellPropertyCategory.SHORT),
|
||||
FILL_FOREGROUND_COLOR(CellPropertyCategory.SHORT),
|
||||
INDENTION(CellPropertyCategory.SHORT),
|
||||
ROTATION(CellPropertyCategory.SHORT),
|
||||
|
||||
FILL_BACKGROUND_COLOR_COLOR(CellPropertyCategory.COLOR),
|
||||
FILL_FOREGROUND_COLOR_COLOR(CellPropertyCategory.COLOR),
|
||||
|
||||
FONT(CellPropertyCategory.INT),
|
||||
|
||||
HIDDEN(CellPropertyCategory.BOOL),
|
||||
LOCKED(CellPropertyCategory.BOOL),
|
||||
WRAP_TEXT(CellPropertyCategory.BOOL),
|
||||
SHRINK_TO_FIT(CellPropertyCategory.BOOL),
|
||||
QUOTE_PREFIXED(CellPropertyCategory.BOOL),
|
||||
|
||||
ALIGNMENT(CellPropertyCategory.OTHER),
|
||||
FILL_PATTERN(CellPropertyCategory.OTHER),
|
||||
VERTICAL_ALIGNMENT(CellPropertyCategory.OTHER);
|
||||
|
||||
CellPropertyType(CellPropertyCategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
private final CellPropertyCategory category;
|
||||
|
||||
public CellPropertyCategory getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 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<CellAddress, Map<String, Object>> _propertyTemplate;
|
||||
private final Map<CellAddress, Map<CellPropertyType, Object>> _propertyTemplate;
|
||||
|
||||
/**
|
||||
* Create a PropertyTemplate object
|
||||
|
@ -73,16 +75,16 @@ public final class PropertyTemplate {
|
|||
*/
|
||||
public PropertyTemplate(PropertyTemplate template) {
|
||||
this();
|
||||
for(Map.Entry<CellAddress, Map<String, Object>> entry : template.getTemplate().entrySet()) {
|
||||
for (Map.Entry<CellAddress, Map<CellPropertyType, Object>> entry : template.getTemplate().entrySet()) {
|
||||
_propertyTemplate.put(new CellAddress(entry.getKey()), cloneCellProperties(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<CellAddress,Map<String, Object>> getTemplate() {
|
||||
private Map<CellAddress, Map<CellPropertyType, Object>> getTemplate() {
|
||||
return _propertyTemplate;
|
||||
}
|
||||
|
||||
private static Map<String, Object> cloneCellProperties(Map<String, Object> properties) {
|
||||
private static Map<CellPropertyType, Object> cloneCellProperties(Map<CellPropertyType, Object> 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 {
|
|||
* </ul>
|
||||
*/
|
||||
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 {
|
|||
* </ul>
|
||||
*/
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
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 {
|
|||
* </ul>
|
||||
*/
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
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<String> properties = new HashSet<>();
|
||||
properties.add(CellUtil.BORDER_TOP);
|
||||
properties.add(CellUtil.BORDER_BOTTOM);
|
||||
properties.add(CellUtil.BORDER_LEFT);
|
||||
properties.add(CellUtil.BORDER_RIGHT);
|
||||
Set<CellPropertyType> 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<CellAddress, Map<String, Object>> entry : _propertyTemplate
|
||||
for (Map.Entry<CellAddress, Map<CellPropertyType, Object>> entry : _propertyTemplate
|
||||
.entrySet()) {
|
||||
CellAddress cellAddress = entry.getKey();
|
||||
if (cellAddress.getRow() < wb.getSpreadsheetVersion().getMaxRows()
|
||||
&& cellAddress.getColumn() < wb.getSpreadsheetVersion()
|
||||
.getMaxColumns()) {
|
||||
Map<String, Object> properties = entry.getValue();
|
||||
.getMaxColumns()) {
|
||||
Map<CellPropertyType, Object> 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 {
|
|||
* </ul>
|
||||
*/
|
||||
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 {
|
|||
* </ul>
|
||||
*/
|
||||
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 {
|
|||
* </ul>
|
||||
*/
|
||||
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<String> 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<CellPropertyType> 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<String, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
Map<CellPropertyType, Object> 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<String> properties) {
|
||||
private void removeProperties(int row, int col, Set<CellPropertyType> properties) {
|
||||
CellAddress cell = new CellAddress(row, col);
|
||||
Map<String, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
Map<CellPropertyType, Object> 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<String, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
Map<CellPropertyType, Object> 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<String, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
Map<CellPropertyType, Object> 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<String, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
Map<CellPropertyType, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
if (cellProperties != null) {
|
||||
Object obj = cellProperties.get(property);
|
||||
if (obj instanceof BorderStyle) {
|
||||
|
@ -881,17 +883,37 @@ public final class PropertyTemplate {
|
|||
|
||||
/**
|
||||
* Retrieves the border style for a given cell
|
||||
*
|
||||
* @deprecated See {@link #getBorderStyle(CellAddress, CellPropertyType)}
|
||||
*/
|
||||
public BorderStyle getBorderStyle(int row, int col, String property) {
|
||||
return getBorderStyle(new CellAddress(row, col), property);
|
||||
@Deprecated
|
||||
public BorderStyle getBorderStyle(CellAddress cell, String propertyName) {
|
||||
return getBorderStyle(cell, CellUtil.namePropertyMap.get(propertyName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the border style for a given cell
|
||||
*/
|
||||
public short getTemplateProperty(CellAddress cell, 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)}
|
||||
*/
|
||||
@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<String, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
Map<CellPropertyType, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
if (cellProperties != null) {
|
||||
Object obj = cellProperties.get(property);
|
||||
if (obj != null) {
|
||||
|
@ -903,11 +925,31 @@ public final class PropertyTemplate {
|
|||
|
||||
/**
|
||||
* Retrieves the border style for a given cell
|
||||
*
|
||||
* @deprecated See {@link #getTemplateProperty(CellAddress, CellPropertyType)}
|
||||
*/
|
||||
public short getTemplateProperty(int row, int col, String property) {
|
||||
@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, 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
|
||||
|
|
|
@ -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;
|
||||
this(CellUtil.namePropertyMap.get(propertyName), value);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Removal(version = "7.0.0")
|
||||
public CellPropertySetter(String propertyName, BorderStyle value) {
|
||||
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(String propertyName, BorderStyle value) {
|
||||
_propertyName = propertyName;
|
||||
|
||||
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);
|
||||
|
|
|
@ -17,31 +17,21 @@
|
|||
|
||||
package org.apache.poi.ss.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
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 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 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;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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<CellPropertyType, Object> 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<CellPropertyType, Object> 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
|
||||
|
|
|
@ -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);
|
||||
|
@ -81,6 +100,333 @@ final class TestPropertyTemplate {
|
|||
pt.getTemplateProperty(0, 0, CellUtil.BOTTOM_BORDER_COLOR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void drawBordersByEnum() 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, 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.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,
|
||||
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.MEDIUM,
|
||||
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.MEDIUM,
|
||||
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));
|
||||
}
|
||||
} else if (i == 2) {
|
||||
if (j == 0) {
|
||||
assertEquals(BorderStyle.THIN,
|
||||
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.THIN,
|
||||
pt.getBorderStyle(i, j,
|
||||
CellPropertyType.BORDER_RIGHT));
|
||||
} else if (j == 2) {
|
||||
assertEquals(BorderStyle.THIN,
|
||||
pt.getBorderStyle(i, j,
|
||||
CellPropertyType.BORDER_TOP));
|
||||
assertEquals(BorderStyle.MEDIUM,
|
||||
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.MEDIUM,
|
||||
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));
|
||||
}
|
||||
} 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);
|
||||
|
@ -408,6 +754,398 @@ final class TestPropertyTemplate {
|
|||
}
|
||||
}
|
||||
|
||||
@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(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(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(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.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(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.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(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.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(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.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(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.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(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.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(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(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(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.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(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(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.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(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.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(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(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(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.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(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(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void drawBorderColors() throws IOException {
|
||||
CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue