* 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.
* 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.
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;
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()) {
}
@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");
}
}
+ @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 {
}
}
+
@Test
- public void testBug66052WithWorkaround() throws IOException, DecoderException {
+ 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");
}
}
+ @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 {
((XSSFColor) cell.getCellStyle().getFillBackgroundColorColor()).getIndex());
}
}
-}
\ No newline at end of file
+}
* 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()
* 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.
--- /dev/null
+/* ====================================================================
+ 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
+
+}
--- /dev/null
+/* ====================================================================
+ 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;
+ }
+
+}
package org.apache.poi.ss.util;
-import java.util.Arrays;
import java.util.Collections;
+import java.util.EnumSet;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.common.Duplicatable;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellCopyContext;
+import org.apache.poi.ss.usermodel.CellCopyPolicy;
+import org.apache.poi.ss.usermodel.CellPropertyType;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Color;
+import org.apache.poi.ss.usermodel.DateUtil;
+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.Hyperlink;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.Beta;
+import org.apache.poi.util.Removal;
/**
* Various utility functions that make working with a cells and rows easier. The various methods
private static final Logger LOGGER = LogManager.getLogger(CellUtil.class);
- // FIXME: Move these constants into an enum
+ private static final Set<CellPropertyType> SHORT_VALUES = EnumSet.of(
+ CellPropertyType.BOTTOM_BORDER_COLOR,
+ CellPropertyType.LEFT_BORDER_COLOR,
+ CellPropertyType.RIGHT_BORDER_COLOR,
+ CellPropertyType.TOP_BORDER_COLOR,
+ CellPropertyType.FILL_FOREGROUND_COLOR,
+ CellPropertyType.FILL_BACKGROUND_COLOR,
+ CellPropertyType.INDENTION,
+ CellPropertyType.DATA_FORMAT,
+ CellPropertyType.ROTATION
+ );
+
+ private static final Set<CellPropertyType> COLOR_VALUES = EnumSet.of(
+ CellPropertyType.FILL_FOREGROUND_COLOR_COLOR,
+ CellPropertyType.FILL_BACKGROUND_COLOR_COLOR
+ );
+
+ private static final Set<CellPropertyType> INT_VALUES = EnumSet.of(
+ CellPropertyType.FONT
+ );
+
+ private static final Set<CellPropertyType> BOOLEAN_VALUES = EnumSet.of(
+ CellPropertyType.LOCKED,
+ CellPropertyType.HIDDEN,
+ CellPropertyType.WRAP_TEXT,
+ CellPropertyType.SHRINK_TO_FIT,
+ CellPropertyType.QUOTE_PREFIXED
+ );
+
+ private static final Set<CellPropertyType> BORDER_TYPE_VALUES = EnumSet.of(
+ CellPropertyType.BORDER_BOTTOM,
+ CellPropertyType.BORDER_LEFT,
+ CellPropertyType.BORDER_RIGHT,
+ CellPropertyType.BORDER_TOP
+ );
+
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#ALIGNMENT} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String ALIGNMENT = "alignment";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#BORDER_BOTTOM} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String BORDER_BOTTOM = "borderBottom";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#BORDER_LEFT} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String BORDER_LEFT = "borderLeft";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#BORDER_RIGHT} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String BORDER_RIGHT = "borderRight";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#BORDER_TOP} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String BORDER_TOP = "borderTop";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#BORDER_BOTTOM} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String BOTTOM_BORDER_COLOR = "bottomBorderColor";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#BOTTOM_BORDER_COLOR} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String LEFT_BORDER_COLOR = "leftBorderColor";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#RIGHT_BORDER_COLOR} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String RIGHT_BORDER_COLOR = "rightBorderColor";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#TOP_BORDER_COLOR} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String TOP_BORDER_COLOR = "topBorderColor";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#DATA_FORMAT} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String DATA_FORMAT = "dataFormat";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#FILL_BACKGROUND_COLOR} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String FILL_BACKGROUND_COLOR = "fillBackgroundColor";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#FILL_FOREGROUND_COLOR} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String FILL_FOREGROUND_COLOR = "fillForegroundColor";
-
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#FILL_BACKGROUND_COLOR_COLOR} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String FILL_BACKGROUND_COLOR_COLOR = "fillBackgroundColorColor";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#FILL_FOREGROUND_COLOR_COLOR} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String FILL_FOREGROUND_COLOR_COLOR = "fillForegroundColorColor";
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#FILL_PATTERN} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String FILL_PATTERN = "fillPattern";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#FONT} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String FONT = "font";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#HIDDEN} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String HIDDEN = "hidden";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#INDENTION} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String INDENTION = "indention";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#LOCKED} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String LOCKED = "locked";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#ROTATION} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String ROTATION = "rotation";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#VERTICAL_ALIGNMENT} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String VERTICAL_ALIGNMENT = "verticalAlignment";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#WRAP_TEXT} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String WRAP_TEXT = "wrapText";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#SHRINK_TO_FIT} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String SHRINK_TO_FIT = "shrinkToFit";
+
+ /**
+ * @deprecated as of POI 5.3.1. Use {@link CellPropertyType#QUOTE_PREFIXED} instead.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static final String QUOTE_PREFIXED = "quotePrefixed";
- private static final Set<String> shortValues = Collections.unmodifiableSet(
- new HashSet<>(Arrays.asList(
- BOTTOM_BORDER_COLOR,
- LEFT_BORDER_COLOR,
- RIGHT_BORDER_COLOR,
- TOP_BORDER_COLOR,
- FILL_FOREGROUND_COLOR,
- FILL_BACKGROUND_COLOR,
- INDENTION,
- DATA_FORMAT,
- ROTATION
- )));
-
- private static final Set<String> colorValues = Collections.unmodifiableSet(
- new HashSet<>(Arrays.asList(
- FILL_FOREGROUND_COLOR_COLOR,
- FILL_BACKGROUND_COLOR_COLOR
- )));
-
- private static final Set<String> intValues = Collections.unmodifiableSet(
- new HashSet<>(Collections.singletonList(
- FONT
- )));
- private static final Set<String> booleanValues = Collections.unmodifiableSet(
- new HashSet<>(Arrays.asList(
- LOCKED,
- HIDDEN,
- WRAP_TEXT,
- SHRINK_TO_FIT,
- QUOTE_PREFIXED
- )));
- private static final Set<String> borderTypeValues = Collections.unmodifiableSet(
- new HashSet<>(Arrays.asList(
- BORDER_BOTTOM,
- BORDER_LEFT,
- BORDER_RIGHT,
- BORDER_TOP
- )));
+ // FIXME Must be deleted along with string constants
+ static final Map<String, CellPropertyType> namePropertyMap = new HashMap<>();
+ static {
+ namePropertyMap.put(ALIGNMENT, CellPropertyType.ALIGNMENT);
+ namePropertyMap.put(BORDER_BOTTOM, CellPropertyType.BORDER_BOTTOM);
+ namePropertyMap.put(BORDER_LEFT, CellPropertyType.BORDER_LEFT);
+ namePropertyMap.put(BORDER_RIGHT, CellPropertyType.BORDER_RIGHT);
+ namePropertyMap.put(BORDER_TOP, CellPropertyType.BORDER_TOP);
+ namePropertyMap.put(BOTTOM_BORDER_COLOR, CellPropertyType.BOTTOM_BORDER_COLOR);
+ namePropertyMap.put(LEFT_BORDER_COLOR, CellPropertyType.LEFT_BORDER_COLOR);
+ namePropertyMap.put(RIGHT_BORDER_COLOR, CellPropertyType.RIGHT_BORDER_COLOR);
+ namePropertyMap.put(TOP_BORDER_COLOR, CellPropertyType.TOP_BORDER_COLOR);
+ namePropertyMap.put(FILL_BACKGROUND_COLOR, CellPropertyType.FILL_BACKGROUND_COLOR);
+ namePropertyMap.put(FILL_FOREGROUND_COLOR, CellPropertyType.FILL_FOREGROUND_COLOR);
+ namePropertyMap.put(FILL_BACKGROUND_COLOR_COLOR, CellPropertyType.FILL_BACKGROUND_COLOR_COLOR);
+ namePropertyMap.put(FILL_FOREGROUND_COLOR_COLOR, CellPropertyType.FILL_FOREGROUND_COLOR_COLOR);
+ namePropertyMap.put(FILL_PATTERN, CellPropertyType.FILL_PATTERN);
+ namePropertyMap.put(FONT, CellPropertyType.FONT);
+ namePropertyMap.put(HIDDEN, CellPropertyType.HIDDEN);
+ namePropertyMap.put(INDENTION, CellPropertyType.INDENTION);
+ namePropertyMap.put(LOCKED, CellPropertyType.LOCKED);
+ namePropertyMap.put(ROTATION, CellPropertyType.ROTATION);
+ namePropertyMap.put(VERTICAL_ALIGNMENT, CellPropertyType.VERTICAL_ALIGNMENT);
+ namePropertyMap.put(SHRINK_TO_FIT, CellPropertyType.SHRINK_TO_FIT);
+ namePropertyMap.put(QUOTE_PREFIXED, CellPropertyType.QUOTE_PREFIXED);
+ }
private static final UnicodeMapping[] unicodeMappings;
// DataFormat is not copied unless policy.isCopyCellStyle is true
if (DateUtil.isCellDateFormatted(srcCell)) {
destCell.setCellValue(srcCell.getDateCellValue());
- }
- else {
+ } else {
destCell.setCellValue(srcCell.getNumericCellValue());
}
break;
// if srcCell doesn't have a hyperlink and destCell has a hyperlink, don't clear destCell's hyperlink
if (srcHyperlink != null) {
if (srcHyperlink instanceof Duplicatable) {
- Hyperlink newHyperlink = (Hyperlink)((Duplicatable)srcHyperlink).copy();
+ Hyperlink newHyperlink = (Hyperlink) ((Duplicatable) srcHyperlink).copy();
destCell.setHyperlink(newHyperlink);
} else {
throw new IllegalStateException("srcCell hyperlink is not an instance of Duplicatable");
if (srcHyperlink == null) {
destCell.setHyperlink(null);
} else if (srcHyperlink instanceof Duplicatable) {
- Hyperlink newHyperlink = (Hyperlink)((Duplicatable)srcHyperlink).copy();
+ Hyperlink newHyperlink = (Hyperlink) ((Duplicatable) srcHyperlink).copy();
destCell.setHyperlink(newHyperlink);
} else {
throw new IllegalStateException("srcCell hyperlink is not an instance of Duplicatable");
/**
* Take a cell, and align it.
- *
+ * <p>
* This is superior to cell.getCellStyle().setAlignment(align) because
* this method will not modify the CellStyle object that may be referenced
* by multiple cells. Instead, this method will search for existing CellStyles
* that match the desired CellStyle, creating a new CellStyle with the desired
* style if no match exists.
- *
+ * </p>
* @param cell the cell to set the alignment for
* @param align the horizontal alignment to use.
*
* @since POI 3.15 beta 3
*/
public static void setAlignment(Cell cell, HorizontalAlignment align) {
- setCellStyleProperty(cell, ALIGNMENT, align);
+ setCellStyleProperty(cell, CellPropertyType.ALIGNMENT, align);
}
/**
* @since POI 3.15 beta 3
*/
public static void setVerticalAlignment(Cell cell, VerticalAlignment align) {
- setCellStyleProperty(cell, VERTICAL_ALIGNMENT, align);
+ setCellStyleProperty(cell, CellPropertyType.VERTICAL_ALIGNMENT, align);
}
/**
// Check if cell belongs to workbook
// (checked in setCellStyleProperty)
- setCellStyleProperty(cell, FONT, fontIndex);
+ setCellStyleProperty(cell, CellPropertyType.FONT, fontIndex);
}
/**
* <p>This is necessary because Excel has an upper limit on the number of styles that it supports.</p>
*
* <p>This function is more efficient than multiple calls to
- * {@link #setCellStyleProperty(Cell, String, Object)}
+ * {@link #setCellStyleProperty(Cell, CellPropertyType, Object)}
* if adding multiple cell styles.</p>
*
* <p>For performance reasons, if this is the only cell in a workbook that uses a cell style,
* </p>
*
* @param cell The cell to change the style of
- * @param properties The properties to be added to a cell style, as {propertyName: propertyValue}.
+ * @param properties The properties to be added to a cell style, as {property: propertyValue}.
* @since POI 3.14 beta 2
+ * @deprecated as of POI 5.3.1. See {@link #setCellStylePropertiesEnum(Cell, Map)}
*/
+ @Deprecated
+ @Removal(version = "7.0.0")
public static void setCellStyleProperties(Cell cell, Map<String, Object> properties) {
+ Map<CellPropertyType, Object> strPropMap = new HashMap<>(properties.size());
+ properties.forEach((k, v) -> strPropMap.put(namePropertyMap.get(k), v));
+ setCellStyleProperties(cell, strPropMap, false);
+ }
+
+ /**
+ * <p>This method attempts to find an existing CellStyle that matches the {@code cell}'s
+ * current style plus styles properties in {@code properties}. A new style is created if the
+ * workbook does not contain a matching style.</p>
+ *
+ * <p>Modifies the cell style of {@code cell} without affecting other cells that use the
+ * same style.</p>
+ *
+ * <p>This is necessary because Excel has an upper limit on the number of styles that it supports.</p>
+ *
+ * <p>This function is more efficient than multiple calls to
+ * {@link #setCellStyleProperty(Cell, CellPropertyType, Object)}
+ * if adding multiple cell styles.</p>
+ *
+ * <p>For performance reasons, if this is the only cell in a workbook that uses a cell style,
+ * this method does NOT remove the old style from the workbook.
+ * <!-- NOT IMPLEMENTED: Unused styles should be
+ * pruned from the workbook with [@link #removeUnusedCellStyles(Workbook)] or
+ * [@link #removeStyleFromWorkbookIfUnused(CellStyle, Workbook)]. -->
+ * </p>
+ *
+ * @param cell The cell to change the style of
+ * @param properties The properties to be added to a cell style, as {property: propertyValue}.
+ * @since POI 5.3.1
+ */
+ public static void setCellStylePropertiesEnum(Cell cell, Map<CellPropertyType, Object> properties) {
setCellStyleProperties(cell, properties, false);
}
- private static void setCellStyleProperties(final Cell cell, final Map<String, Object> properties,
+ private static void setCellStyleProperties(final Cell cell, final Map<CellPropertyType, Object> properties,
final boolean disableNullColorCheck) {
Workbook workbook = cell.getSheet().getWorkbook();
CellStyle originalStyle = cell.getCellStyle();
CellStyle newStyle = null;
- Map<String, Object> values = getFormatProperties(originalStyle);
- if (properties.containsKey(FILL_FOREGROUND_COLOR_COLOR) && properties.get(FILL_FOREGROUND_COLOR_COLOR) == null) {
- values.remove(FILL_FOREGROUND_COLOR);
+ Map<CellPropertyType, Object> values = getFormatProperties(originalStyle);
+ if (properties.containsKey(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR) && properties.get(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR) == null) {
+ values.remove(CellPropertyType.FILL_FOREGROUND_COLOR);
}
- if (properties.containsKey(FILL_FOREGROUND_COLOR) && !properties.containsKey(FILL_FOREGROUND_COLOR_COLOR)) {
- values.remove(FILL_FOREGROUND_COLOR_COLOR);
+ if (properties.containsKey(CellPropertyType.FILL_FOREGROUND_COLOR) && !properties.containsKey(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR)) {
+ values.remove(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR);
}
- if (properties.containsKey(FILL_BACKGROUND_COLOR_COLOR) && properties.get(FILL_BACKGROUND_COLOR_COLOR) == null) {
- values.remove(FILL_BACKGROUND_COLOR);
+ if (properties.containsKey(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR) && properties.get(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR) == null) {
+ values.remove(CellPropertyType.FILL_BACKGROUND_COLOR);
}
- if (properties.containsKey(FILL_BACKGROUND_COLOR) && !properties.containsKey(FILL_BACKGROUND_COLOR_COLOR)) {
- values.remove(FILL_BACKGROUND_COLOR_COLOR);
+ if (properties.containsKey(CellPropertyType.FILL_BACKGROUND_COLOR) && !properties.containsKey(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR)) {
+ values.remove(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR);
}
putAll(properties, values);
for (int i = 0; i < numberCellStyles; i++) {
CellStyle wbStyle = workbook.getCellStyleAt(i);
- Map<String, Object> wbStyleMap = getFormatProperties(wbStyle);
+ Map<CellPropertyType, Object> wbStyleMap = getFormatProperties(wbStyle);
// the desired style already exists in the workbook. Use the existing style.
if (styleMapsMatch(wbStyleMap, values, disableNullColorCheck)) {
cell.setCellStyle(newStyle);
}
- private static boolean styleMapsMatch(final Map<String, Object> newProps,
- final Map<String, Object> storedProps, final boolean disableNullColorCheck) {
- final Map<String, Object> map1Copy = new HashMap<>(newProps);
- final Map<String, Object> map2Copy = new HashMap<>(storedProps);
- final Object backColor1 = map1Copy.remove(FILL_BACKGROUND_COLOR_COLOR);
- final Object backColor2 = map2Copy.remove(FILL_BACKGROUND_COLOR_COLOR);
- final Object foreColor1 = map1Copy.remove(FILL_FOREGROUND_COLOR_COLOR);
- final Object foreColor2 = map2Copy.remove(FILL_FOREGROUND_COLOR_COLOR);
+ private static boolean styleMapsMatch(final Map<CellPropertyType, Object> newProps,
+ final Map<CellPropertyType, Object> storedProps, final boolean disableNullColorCheck) {
+ final Map<CellPropertyType, Object> map1Copy = new HashMap<>(newProps);
+ final Map<CellPropertyType, Object> map2Copy = new HashMap<>(storedProps);
+ final Object backColor1 = map1Copy.remove(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR);
+ final Object backColor2 = map2Copy.remove(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR);
+ final Object foreColor1 = map1Copy.remove(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR);
+ final Object foreColor2 = map2Copy.remove(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR);
if (map1Copy.equals(map2Copy)) {
final boolean backColorsMatch = (!disableNullColorCheck && backColor2 == null)
|| Objects.equals(backColor1, backColor2);
* same style.</p>
*
* <p>If setting more than one cell style property on a cell, use
- * {@link #setCellStyleProperties(Cell, Map)},
+ * {@link #setCellStylePropertiesEnum(Cell, Map)},
* which is faster and does not add unnecessary intermediate CellStyles to the workbook.</p>
*
* @param cell The cell that is to be changed.
- * @param propertyName The name of the property that is to be changed.
+ * @param property The name of the property that is to be changed.
* @param propertyValue The value of the property that is to be changed.
+ *
+ * @since POI 5.3.1
*/
- public static void setCellStyleProperty(Cell cell, String propertyName, Object propertyValue) {
+ public static void setCellStyleProperty(Cell cell, CellPropertyType property, Object propertyValue) {
boolean disableNullColorCheck = false;
- final Map<String, Object> propMap;
- if (CellUtil.FILL_FOREGROUND_COLOR_COLOR.equals(propertyName) && propertyValue == null) {
+ final Map<CellPropertyType, Object> propMap;
+ if (CellPropertyType.FILL_FOREGROUND_COLOR_COLOR.equals(property) && propertyValue == null) {
disableNullColorCheck = true;
propMap = new HashMap<>();
- propMap.put(CellUtil.FILL_FOREGROUND_COLOR_COLOR, null);
- propMap.put(CellUtil.FILL_FOREGROUND_COLOR, null);
- } else if (CellUtil.FILL_BACKGROUND_COLOR_COLOR.equals(propertyName) && propertyValue == null) {
+ propMap.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, null);
+ propMap.put(CellPropertyType.FILL_FOREGROUND_COLOR, null);
+ } else if (CellPropertyType.FILL_BACKGROUND_COLOR_COLOR.equals(property) && propertyValue == null) {
disableNullColorCheck = true;
propMap = new HashMap<>();
- propMap.put(CellUtil.FILL_BACKGROUND_COLOR_COLOR, null);
- propMap.put(CellUtil.FILL_BACKGROUND_COLOR, null);
+ propMap.put(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR, null);
+ propMap.put(CellPropertyType.FILL_BACKGROUND_COLOR, null);
} else {
- propMap = Collections.singletonMap(propertyName, propertyValue);
+ propMap = Collections.singletonMap(property, propertyValue);
}
setCellStyleProperties(cell, propMap, disableNullColorCheck);
}
+ /**
+ * <p>This method attempts to find an existing CellStyle that matches the {@code cell}'s
+ * current style plus a single style property {@code propertyName} with value
+ * {@code propertyValue}.
+ * A new style is created if the workbook does not contain a matching style.</p>
+ *
+ * <p>Modifies the cell style of {@code cell} without affecting other cells that use the
+ * same style.</p>
+ *
+ * <p>If setting more than one cell style property on a cell, use
+ * {@link #setCellStylePropertiesEnum(Cell, Map)},
+ * which is faster and does not add unnecessary intermediate CellStyles to the workbook.</p>
+ *
+ * @param cell The cell that is to be changed.
+ * @param propertyName The name of the property that is to be changed.
+ * @param propertyValue The value of the property that is to be changed.
+ * @deprecated as of POI 5.3.1. See {@link #setCellStyleProperty(Cell, CellPropertyType, Object)}
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
+ public static void setCellStyleProperty(Cell cell, String propertyName, Object propertyValue) {
+ setCellStyleProperty(cell, namePropertyMap.get(propertyName), propertyValue);
+ }
+
/**
* Returns a map containing the format properties of the given cell style.
* The returned map is not tied to {@code style}, so subsequent changes
* map will not modify the cell style. The returned map is mutable.
*
* @param style cell style
- * @return map of format properties (String -> Object)
+ * @return map of format properties (CellPropertyType -> Object)
* @see #setFormatProperties(CellStyle, Workbook, Map)
*/
- private static Map<String, Object> getFormatProperties(CellStyle style) {
- Map<String, Object> properties = new HashMap<>();
- put(properties, ALIGNMENT, style.getAlignment());
- put(properties, VERTICAL_ALIGNMENT, style.getVerticalAlignment());
- put(properties, BORDER_BOTTOM, style.getBorderBottom());
- put(properties, BORDER_LEFT, style.getBorderLeft());
- put(properties, BORDER_RIGHT, style.getBorderRight());
- put(properties, BORDER_TOP, style.getBorderTop());
- put(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor());
- put(properties, DATA_FORMAT, style.getDataFormat());
- put(properties, FILL_PATTERN, style.getFillPattern());
-
- put(properties, FILL_FOREGROUND_COLOR, style.getFillForegroundColor());
- put(properties, FILL_BACKGROUND_COLOR, style.getFillBackgroundColor());
- put(properties, FILL_FOREGROUND_COLOR_COLOR, style.getFillForegroundColorColor());
- put(properties, FILL_BACKGROUND_COLOR_COLOR, style.getFillBackgroundColorColor());
-
- put(properties, FONT, style.getFontIndex());
- put(properties, HIDDEN, style.getHidden());
- put(properties, INDENTION, style.getIndention());
- put(properties, LEFT_BORDER_COLOR, style.getLeftBorderColor());
- put(properties, LOCKED, style.getLocked());
- put(properties, RIGHT_BORDER_COLOR, style.getRightBorderColor());
- put(properties, ROTATION, style.getRotation());
- put(properties, TOP_BORDER_COLOR, style.getTopBorderColor());
- put(properties, WRAP_TEXT, style.getWrapText());
- put(properties, SHRINK_TO_FIT, style.getShrinkToFit());
- put(properties, QUOTE_PREFIXED, style.getQuotePrefixed());
+ private static Map<CellPropertyType, Object> getFormatProperties(CellStyle style) {
+ Map<CellPropertyType, Object> properties = new HashMap<>();
+ put(properties, CellPropertyType.ALIGNMENT, style.getAlignment());
+ put(properties, CellPropertyType.VERTICAL_ALIGNMENT, style.getVerticalAlignment());
+ put(properties, CellPropertyType.BORDER_BOTTOM, style.getBorderBottom());
+ put(properties, CellPropertyType.BORDER_LEFT, style.getBorderLeft());
+ put(properties, CellPropertyType.BORDER_RIGHT, style.getBorderRight());
+ put(properties, CellPropertyType.BORDER_TOP, style.getBorderTop());
+ put(properties, CellPropertyType.BOTTOM_BORDER_COLOR, style.getBottomBorderColor());
+ put(properties, CellPropertyType.DATA_FORMAT, style.getDataFormat());
+ put(properties, CellPropertyType.FILL_PATTERN, style.getFillPattern());
+
+ put(properties, CellPropertyType.FILL_FOREGROUND_COLOR, style.getFillForegroundColor());
+ put(properties, CellPropertyType.FILL_BACKGROUND_COLOR, style.getFillBackgroundColor());
+ put(properties, CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, style.getFillForegroundColorColor());
+ put(properties, CellPropertyType.FILL_BACKGROUND_COLOR_COLOR, style.getFillBackgroundColorColor());
+
+ put(properties, CellPropertyType.FONT, style.getFontIndex());
+ put(properties, CellPropertyType.HIDDEN, style.getHidden());
+ put(properties, CellPropertyType.INDENTION, style.getIndention());
+ put(properties, CellPropertyType.LEFT_BORDER_COLOR, style.getLeftBorderColor());
+ put(properties, CellPropertyType.LOCKED, style.getLocked());
+ put(properties, CellPropertyType.RIGHT_BORDER_COLOR, style.getRightBorderColor());
+ put(properties, CellPropertyType.ROTATION, style.getRotation());
+ put(properties, CellPropertyType.TOP_BORDER_COLOR, style.getTopBorderColor());
+ put(properties, CellPropertyType.WRAP_TEXT, style.getWrapText());
+ put(properties, CellPropertyType.SHRINK_TO_FIT, style.getShrinkToFit());
+ put(properties, CellPropertyType.QUOTE_PREFIXED, style.getQuotePrefixed());
return properties;
}
* @param dest the property map to copy into
* @since POI 3.15 beta 3
*/
- private static void putAll(final Map<String, Object> src, Map<String, Object> dest) {
- for (final String key : src.keySet()) {
- if (shortValues.contains(key)) {
+ private static void putAll(final Map<CellPropertyType, Object> src, Map<CellPropertyType, Object> dest) {
+ for (final CellPropertyType key : src.keySet()) {
+ if (SHORT_VALUES.contains(key)) {
dest.put(key, nullableShort(src, key));
- } else if (colorValues.contains(key)) {
+ } else if (COLOR_VALUES.contains(key)) {
dest.put(key, getColor(src, key));
- } else if (intValues.contains(key)) {
+ } else if (INT_VALUES.contains(key)) {
dest.put(key, getInt(src, key));
- } else if (booleanValues.contains(key)) {
+ } else if (BOOLEAN_VALUES.contains(key)) {
dest.put(key, getBoolean(src, key));
- } else if (borderTypeValues.contains(key)) {
+ } else if (BORDER_TYPE_VALUES.contains(key)) {
dest.put(key, getBorderStyle(src, key));
- } else if (ALIGNMENT.equals(key)) {
+ } else if (CellPropertyType.ALIGNMENT.equals(key)) {
dest.put(key, getHorizontalAlignment(src, key));
- } else if (VERTICAL_ALIGNMENT.equals(key)) {
+ } else if (CellPropertyType.VERTICAL_ALIGNMENT.equals(key)) {
dest.put(key, getVerticalAlignment(src, key));
- } else if (FILL_PATTERN.equals(key)) {
+ } else if (CellPropertyType.FILL_PATTERN.equals(key)) {
dest.put(key, getFillPattern(src, key));
} else {
LOGGER.atInfo().log("Ignoring unrecognized CellUtil format properties key: {}", key);
*
* @param style cell style
* @param workbook parent workbook
- * @param properties map of format properties (String -> Object)
+ * @param properties map of format properties (CellPropertyType -> Object)
* @see #getFormatProperties(CellStyle)
*/
- private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
- style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
- style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
- style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
- style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
- style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
- style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
- style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
- style.setDataFormat(getShort(properties, DATA_FORMAT));
- style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
-
- Short fillForeColorShort = nullableShort(properties, FILL_FOREGROUND_COLOR);
+ private static void setFormatProperties(CellStyle style, Workbook workbook, Map<CellPropertyType, Object> properties) {
+ style.setAlignment(getHorizontalAlignment(properties, CellPropertyType.ALIGNMENT));
+ style.setVerticalAlignment(getVerticalAlignment(properties, CellPropertyType.VERTICAL_ALIGNMENT));
+ style.setBorderBottom(getBorderStyle(properties, CellPropertyType.BORDER_BOTTOM));
+ style.setBorderLeft(getBorderStyle(properties, CellPropertyType.BORDER_LEFT));
+ style.setBorderRight(getBorderStyle(properties, CellPropertyType.BORDER_RIGHT));
+ style.setBorderTop(getBorderStyle(properties, CellPropertyType.BORDER_TOP));
+ style.setBottomBorderColor(getShort(properties, CellPropertyType.BOTTOM_BORDER_COLOR));
+ style.setDataFormat(getShort(properties, CellPropertyType.DATA_FORMAT));
+ style.setFillPattern(getFillPattern(properties, CellPropertyType.FILL_PATTERN));
+
+ Short fillForeColorShort = nullableShort(properties, CellPropertyType.FILL_FOREGROUND_COLOR);
if (fillForeColorShort != null) {
style.setFillForegroundColor(fillForeColorShort);
}
- Short fillBackColorShort = nullableShort(properties, FILL_BACKGROUND_COLOR);
+ Short fillBackColorShort = nullableShort(properties, CellPropertyType.FILL_BACKGROUND_COLOR);
if (fillBackColorShort != null) {
style.setFillBackgroundColor(fillBackColorShort);
}
- Color foregroundFillColor = getColor(properties, FILL_FOREGROUND_COLOR_COLOR);
- Color backgroundFillColor = getColor(properties, FILL_BACKGROUND_COLOR_COLOR);
+ Color foregroundFillColor = getColor(properties, CellPropertyType.FILL_FOREGROUND_COLOR_COLOR);
+ Color backgroundFillColor = getColor(properties, CellPropertyType.FILL_BACKGROUND_COLOR_COLOR);
if (foregroundFillColor != null) {
try {
}
}
- style.setFont(workbook.getFontAt(getInt(properties, FONT)));
- style.setHidden(getBoolean(properties, HIDDEN));
- style.setIndention(getShort(properties, INDENTION));
- style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
- style.setLocked(getBoolean(properties, LOCKED));
- style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
- style.setRotation(getShort(properties, ROTATION));
- style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
- style.setWrapText(getBoolean(properties, WRAP_TEXT));
- style.setShrinkToFit(getBoolean(properties, SHRINK_TO_FIT));
- style.setQuotePrefixed(getBoolean(properties, QUOTE_PREFIXED));
+ style.setFont(workbook.getFontAt(getInt(properties, CellPropertyType.FONT)));
+ style.setHidden(getBoolean(properties, CellPropertyType.HIDDEN));
+ style.setIndention(getShort(properties, CellPropertyType.INDENTION));
+ style.setLeftBorderColor(getShort(properties, CellPropertyType.LEFT_BORDER_COLOR));
+ style.setLocked(getBoolean(properties, CellPropertyType.LOCKED));
+ style.setRightBorderColor(getShort(properties, CellPropertyType.RIGHT_BORDER_COLOR));
+ style.setRotation(getShort(properties, CellPropertyType.ROTATION));
+ style.setTopBorderColor(getShort(properties, CellPropertyType.TOP_BORDER_COLOR));
+ style.setWrapText(getBoolean(properties, CellPropertyType.WRAP_TEXT));
+ style.setShrinkToFit(getBoolean(properties, CellPropertyType.SHRINK_TO_FIT));
+ style.setQuotePrefixed(getBoolean(properties, CellPropertyType.QUOTE_PREFIXED));
}
/**
* Utility method that returns the named short value from the given map.
*
- * @param properties map of named properties (String -> Object)
- * @param name property name
+ * @param properties map of named properties (CellPropertyType -> Object)
+ * @param property property
* @return zero if the property does not exist, or is not a {@link Short}
* otherwise the property value
*/
- private static short getShort(Map<String, Object> properties, String name) {
- Object value = properties.get(name);
+ private static short getShort(Map<CellPropertyType, Object> properties, CellPropertyType property) {
+ Object value = properties.get(property);
if (value instanceof Number) {
return ((Number) value).shortValue();
}
return 0;
}
- private static Short nullableShort(Map<String, Object> properties, String name) {
- Object value = properties.get(name);
+ private static Short nullableShort(Map<CellPropertyType, Object> properties, CellPropertyType property) {
+ Object value = properties.get(property);
if (value instanceof Short) {
return (Short) value;
}
}
return null;
}
-
+
/**
* Utility method that returns the named Color value from the given map.
*
- * @param properties map of named properties (String -> Object)
- * @param name property name
+ * @param properties map of named properties (CellPropertyType -> Object)
+ * @param property property
* @return null if the property does not exist, or is not a {@link Color}
* otherwise the property value
*/
- private static Color getColor(Map<String, Object> properties, String name) {
- Object value = properties.get(name);
+ private static Color getColor(Map<CellPropertyType, Object> properties, CellPropertyType property) {
+ Object value = properties.get(property);
if (value instanceof Color) {
return (Color) value;
}
/**
* Utility method that returns the named int value from the given map.
*
- * @param properties map of named properties (String -> Object)
- * @param name property name
+ * @param properties map of named properties (CellPropertyType -> Object)
+ * @param property property
* @return zero if the property does not exist, or is not a {@link Integer}
* otherwise the property value
*/
- private static int getInt(Map<String, Object> properties, String name) {
- Object value = properties.get(name);
+ private static int getInt(Map<CellPropertyType, Object> properties, CellPropertyType property) {
+ Object value = properties.get(property);
if (value instanceof Number) {
return ((Number) value).intValue();
}
/**
* Utility method that returns the named BorderStyle value from the given map.
*
- * @param properties map of named properties (String -> Object)
- * @param name property name
+ * @param properties map of named properties (CellPropertyType -> Object)
+ * @param property property
* @return Border style if set, otherwise {@link BorderStyle#NONE}
*/
- private static BorderStyle getBorderStyle(Map<String, Object> properties, String name) {
- Object value = properties.get(name);
+ private static BorderStyle getBorderStyle(Map<CellPropertyType, Object> properties, CellPropertyType property) {
+ Object value = properties.get(property);
BorderStyle border;
if (value instanceof BorderStyle) {
border = (BorderStyle) value;
}
// @deprecated 3.15 beta 2. getBorderStyle will only work on BorderStyle enums instead of codes in the future.
else if (value instanceof Short) {
- LOGGER.atWarn().log("Deprecation warning: CellUtil properties map uses Short values for {}. Should use BorderStyle enums instead.", name);
+ LOGGER.atWarn().log("Deprecation warning: CellUtil properties map uses Short values for {}. Should use BorderStyle enums instead.", property);
short code = (Short) value;
border = BorderStyle.valueOf(code);
- }
- else if (value == null) {
+ } else if (value == null) {
border = BorderStyle.NONE;
- }
- else {
+ } else {
throw new IllegalStateException("Unexpected border style class. Must be BorderStyle or Short (deprecated).");
}
return border;
/**
* Utility method that returns the named FillPatternType value from the given map.
*
- * @param properties map of named properties (String -> Object)
- * @param name property name
+ * @param properties map of named properties (CellPropertyType -> Object)
+ * @param property property
* @return FillPatternType style if set, otherwise {@link FillPatternType#NO_FILL}
* @since POI 3.15 beta 3
*/
- private static FillPatternType getFillPattern(Map<String, Object> properties, String name) {
- Object value = properties.get(name);
+ private static FillPatternType getFillPattern(Map<CellPropertyType, Object> properties, CellPropertyType property) {
+ Object value = properties.get(property);
FillPatternType pattern;
if (value instanceof FillPatternType) {
pattern = (FillPatternType) value;
}
// @deprecated 3.15 beta 2. getFillPattern will only work on FillPatternType enums instead of codes in the future.
else if (value instanceof Short) {
- LOGGER.atWarn().log("Deprecation warning: CellUtil properties map uses Short values for {}. Should use FillPatternType enums instead.", name);
+ LOGGER.atWarn().log("Deprecation warning: CellUtil properties map uses Short values for {}. Should use FillPatternType enums instead.", property);
short code = (Short) value;
pattern = FillPatternType.forInt(code);
- }
- else if (value == null) {
+ } else if (value == null) {
pattern = FillPatternType.NO_FILL;
- }
- else {
+ } else {
throw new IllegalStateException("Unexpected fill pattern style class. Must be FillPatternType or Short (deprecated).");
}
return pattern;
/**
* Utility method that returns the named HorizontalAlignment value from the given map.
*
- * @param properties map of named properties (String -> Object)
- * @param name property name
+ * @param properties map of named properties (CellPropertyType -> Object)
+ * @param property property
* @return HorizontalAlignment style if set, otherwise {@link HorizontalAlignment#GENERAL}
* @since POI 3.15 beta 3
*/
- private static HorizontalAlignment getHorizontalAlignment(Map<String, Object> properties, String name) {
- Object value = properties.get(name);
+ private static HorizontalAlignment getHorizontalAlignment(Map<CellPropertyType, Object> properties, CellPropertyType property) {
+ Object value = properties.get(property);
HorizontalAlignment align;
if (value instanceof HorizontalAlignment) {
align = (HorizontalAlignment) value;
}
// @deprecated 3.15 beta 2. getHorizontalAlignment will only work on HorizontalAlignment enums instead of codes in the future.
else if (value instanceof Short) {
- LOGGER.atWarn().log("Deprecation warning: CellUtil properties map used a Short value for {}. Should use HorizontalAlignment enums instead.", name);
+ LOGGER.atWarn().log("Deprecation warning: CellUtil properties map used a Short value for {}. Should use HorizontalAlignment enums instead.", property);
short code = (Short) value;
align = HorizontalAlignment.forInt(code);
- }
- else if (value == null) {
+ } else if (value == null) {
align = HorizontalAlignment.GENERAL;
- }
- else {
+ } else {
throw new IllegalStateException("Unexpected horizontal alignment style class. Must be HorizontalAlignment or Short (deprecated).");
}
return align;
/**
* Utility method that returns the named VerticalAlignment value from the given map.
*
- * @param properties map of named properties (String -> Object)
- * @param name property name
+ * @param properties map of named properties (CellPropertyType -> Object)
+ * @param property property
* @return VerticalAlignment style if set, otherwise {@link VerticalAlignment#BOTTOM}
* @since POI 3.15 beta 3
*/
- private static VerticalAlignment getVerticalAlignment(Map<String, Object> properties, String name) {
- Object value = properties.get(name);
+ private static VerticalAlignment getVerticalAlignment(Map<CellPropertyType, Object> properties, CellPropertyType property) {
+ Object value = properties.get(property);
VerticalAlignment align;
if (value instanceof VerticalAlignment) {
align = (VerticalAlignment) value;
}
// @deprecated 3.15 beta 2. getVerticalAlignment will only work on VerticalAlignment enums instead of codes in the future.
else if (value instanceof Short) {
- LOGGER.atWarn().log("Deprecation warning: CellUtil properties map used a Short value for {}. Should use VerticalAlignment enums instead.", name);
+ LOGGER.atWarn().log("Deprecation warning: CellUtil properties map used a Short value for {}. Should use VerticalAlignment enums instead.", property);
short code = (Short) value;
align = VerticalAlignment.forInt(code);
- }
- else if (value == null) {
+ } else if (value == null) {
align = VerticalAlignment.BOTTOM;
- }
- else {
+ } else {
throw new IllegalStateException("Unexpected vertical alignment style class. Must be VerticalAlignment or Short (deprecated).");
}
return align;
/**
* Utility method that returns the named boolean value from the given map.
*
- * @param properties map of properties (String -> Object)
- * @param name property name
+ * @param properties map of properties (CellPropertyType -> Object)
+ * @param property property
* @return false if the property does not exist, or is not a {@link Boolean},
* true otherwise
*/
- private static boolean getBoolean(Map<String, Object> properties, String name) {
- Object value = properties.get(name);
+ private static boolean getBoolean(Map<CellPropertyType, Object> properties, CellPropertyType property) {
+ Object value = properties.get(property);
//noinspection SimplifiableIfStatement
if (value instanceof Boolean) {
return (Boolean) value;
/**
* Utility method that puts the given value to the given map.
*
- * @param properties map of properties (String -> Object)
- * @param name property name
+ * @param properties map of properties (CellPropertyType -> Object)
+ * @param property property
* @param value property value
*/
- private static void put(Map<String, Object> properties, String name, Object value) {
- properties.put(name, value);
+ private static void put(Map<CellPropertyType, Object> properties, CellPropertyType property, Object value) {
+ properties.put(property, value);
}
/**
static {
unicodeMappings = new UnicodeMapping[] {
- um("alpha", "\u03B1" ),
- um("beta", "\u03B2" ),
- um("gamma", "\u03B3" ),
- um("delta", "\u03B4" ),
- um("epsilon", "\u03B5" ),
- um("zeta", "\u03B6" ),
- um("eta", "\u03B7" ),
- um("theta", "\u03B8" ),
- um("iota", "\u03B9" ),
- um("kappa", "\u03BA" ),
- um("lambda", "\u03BB" ),
- um("mu", "\u03BC" ),
- um("nu", "\u03BD" ),
- um("xi", "\u03BE" ),
- um("omicron", "\u03BF" ),
+ um("alpha", "\u03B1" ),
+ um("beta", "\u03B2" ),
+ um("gamma", "\u03B3" ),
+ um("delta", "\u03B4" ),
+ um("epsilon", "\u03B5" ),
+ um("zeta", "\u03B6" ),
+ um("eta", "\u03B7" ),
+ um("theta", "\u03B8" ),
+ um("iota", "\u03B9" ),
+ um("kappa", "\u03BA" ),
+ um("lambda", "\u03BB" ),
+ um("mu", "\u03BC" ),
+ um("nu", "\u03BD" ),
+ um("xi", "\u03BE" ),
+ um("omicron", "\u03BF" ),
};
}
+
private static UnicodeMapping um(String entityName, String resolvedValue) {
return new UnicodeMapping(entityName, resolvedValue);
}
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
* 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
*/
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);
}
* 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;
}
}
* 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);
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);
}
}
}
* - 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);
}
}
}
* - 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);
}
}
}
* - 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);
}
}
}
* </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");
}
}
* </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);
- }
- if (extent == BorderExtent.ALL || i < lastRow) {
- drawBottomBorder(row, borderType);
+ case ALL:
+ case INSIDE:
+ int firstRow = range.getFirstRow();
+ int lastRow = range.getLastRow();
+ int firstCol = range.getFirstColumn();
+ int lastCol = range.getLastColumn();
+ for (int i = firstRow; i <= lastRow; i++) {
+ CellRangeAddress row = new CellRangeAddress(i, i, firstCol,
+ lastCol);
+ if (extent == BorderExtent.ALL || i > firstRow) {
+ drawTopBorder(row, borderType);
+ }
+ if (extent == BorderExtent.ALL || i < lastRow) {
+ drawBottomBorder(row, borderType);
+ }
}
- }
- break;
- default:
- throw new IllegalArgumentException(
- "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
}
}
* </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);
- }
- if (extent == BorderExtent.ALL || i < lastCol) {
- drawRightBorder(row, borderType);
+ case ALL:
+ case INSIDE:
+ int firstRow = range.getFirstRow();
+ int lastRow = range.getLastRow();
+ int firstCol = range.getFirstColumn();
+ int lastCol = range.getLastColumn();
+ for (int i = firstCol; i <= lastCol; i++) {
+ CellRangeAddress row = new CellRangeAddress(firstRow, lastRow,
+ i, i);
+ if (extent == BorderExtent.ALL || i > firstCol) {
+ drawLeftBorder(row, borderType);
+ }
+ if (extent == BorderExtent.ALL || i < lastCol) {
+ drawRightBorder(row, borderType);
+ }
}
- }
- break;
- default:
- throw new IllegalArgumentException(
- "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported PropertyTemplate.Extent, valid Extents are ALL and INSIDE");
}
}
* @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++) {
*/
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);
}
}
}
* 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;
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
* </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");
}
}
* </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");
}
}
* </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");
}
}
* @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++) {
/**
* 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<>();
}
* 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()) {
* 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;
* 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;
/**
* 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) {
return value;
}
+ /**
+ * Retrieves the border style for a given cell
+ *
+ * @deprecated See {@link #getBorderStyle(CellAddress, CellPropertyType)}
+ */
+ @Deprecated
+ public BorderStyle getBorderStyle(CellAddress cell, String propertyName) {
+ return getBorderStyle(cell, CellUtil.namePropertyMap.get(propertyName));
+ }
+
/**
* Retrieves the border style for a given cell
*/
- public BorderStyle getBorderStyle(int row, int col, String property) {
+ public BorderStyle getBorderStyle(int row, int col, CellPropertyType property) {
return getBorderStyle(new CellAddress(row, col), property);
}
/**
* Retrieves the border style for a given cell
+ *
+ * @deprecated See {@link #getBorderStyle(int, int, CellPropertyType)}
*/
- public short getTemplateProperty(CellAddress cell, String property) {
+ @Deprecated
+ public BorderStyle getBorderStyle(int row, int col, String propertyName) {
+ return getBorderStyle(new CellAddress(row, col), CellUtil.namePropertyMap.get(propertyName));
+ }
+
+ /**
+ * Retrieves the border style for a given cell
+ */
+ public short getTemplateProperty(CellAddress cell, CellPropertyType property) {
short value = 0;
- Map<String, Object> cellProperties = _propertyTemplate.get(cell);
+ Map<CellPropertyType, Object> cellProperties = _propertyTemplate.get(cell);
if (cellProperties != null) {
Object obj = cellProperties.get(property);
if (obj != null) {
return value;
}
+ /**
+ * Retrieves the border style for a given cell
+ *
+ * @deprecated See {@link #getTemplateProperty(CellAddress, CellPropertyType)}
+ */
+ @Deprecated
+ public short getTemplateProperty(CellAddress cell, String propertyName) {
+ return getTemplateProperty(cell, CellUtil.namePropertyMap.get(propertyName));
+ }
+
/**
* Retrieves the border style for a given cell
*/
- public short getTemplateProperty(int row, int col, String property) {
+ public short getTemplateProperty(int row, int col, CellPropertyType property) {
return getTemplateProperty(new CellAddress(row, col), property);
}
+ /**
+ * Retrieves the border style for a given cell
+ *
+ * @deprecated See {@link #getTemplateProperty(int, int, CellPropertyType)}
+ */
+ @Deprecated
+ public short getTemplateProperty(int row, int col, String propertyName) {
+ return getTemplateProperty(new CellAddress(row, col), CellUtil.namePropertyMap.get(propertyName));
+ }
+
/**
* Converts a Short object to a short value or 0 if the object is not a
* Short
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.
*/
private static final class CellPropertySetter {
- private final String _propertyName;
+ private final CellPropertyType property;
private final Object _propertyValue;
-
+ @Deprecated
public CellPropertySetter(String propertyName, int value) {
- _propertyName = propertyName;
- _propertyValue = Integer.valueOf(value);
+ this(CellUtil.namePropertyMap.get(propertyName), value);
}
+
+ @Deprecated
+ @Removal(version = "7.0.0")
public CellPropertySetter(String propertyName, BorderStyle value) {
- _propertyName = propertyName;
+ this(CellUtil.namePropertyMap.get(propertyName), value);
+ }
+
+ /**
+ * @param property The property to set
+ * @param value The value to set the property to
+ * @since POI 5.3.1
+ */
+ public CellPropertySetter(CellPropertyType property, int value) {
+ this.property = property;
+ _propertyValue = Integer.valueOf(value);
+ }
+
+ public CellPropertySetter(CellPropertyType property, BorderStyle value) {
+ this.property = property;
_propertyValue = value;
}
public void setProperty(Row row, int column) {
// create cell if it does not exist
Cell cell = CellUtil.getCell(row, column);
- CellUtil.setCellStyleProperty(cell, _propertyName, _propertyValue);
+ CellUtil.setCellStyleProperty(cell, property, _propertyValue);
}
}
/**
* Sets the left border style for a region of cells by manipulating the cell style of the individual
* cells on the left
- *
+ *
* @param border The new border
* @param region The region that should have the border
* @param sheet The sheet that the region is on.
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);
}
/**
* 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.
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);
}
/**
* 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.
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);
}
/**
* 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.
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);
}
/**
* 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.
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);
/**
* 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.
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);
/**
* 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.
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);
/**
* 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.
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);
package org.apache.poi.ss.util;
+import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.ss.usermodel.*;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.poi.ss.ITestDataProvider;
-import org.apache.poi.ss.usermodel.BorderStyle;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.FillPatternType;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.VerticalAlignment;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.junit.jupiter.api.Test;
/**
* Tests Spreadsheet CellUtil
_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()) {
}
}
+ @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()) {
}
}
+ @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()) {
}
}
+ @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()) {
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);
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());
}
}
+ @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()) {
@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
/**
* 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
/**
* bug 63268
+ *
* @since POI 4.1.0
*/
@Test
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;
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
*
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);
}
@Test
- void drawBorders() throws IOException {
+ void drawBordersByEnum() throws IOException {
CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
PropertyTemplate pt = new PropertyTemplate();
pt.drawBorders(a1c3, BorderStyle.THIN,
for (int j = 0; j <= 2; j++) {
assertEquals(4, pt.getNumBorders(i, j));
assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
}
}
pt.drawBorders(a1c3, BorderStyle.MEDIUM,
if (j == 0) {
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
} else if (j == 2) {
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
} else {
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
}
} else if (i == 2) {
if (j == 0) {
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
} else if (j == 2) {
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
} else {
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
+ CellPropertyType.BORDER_TOP));
assertEquals(BorderStyle.MEDIUM,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
+ CellPropertyType.BORDER_BOTTOM));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
+ CellPropertyType.BORDER_LEFT));
assertEquals(BorderStyle.THIN,
pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ CellPropertyType.BORDER_RIGHT));
+ }
+ } else {
+ if (j == 0) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_BOTTOM));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_RIGHT));
+ } else {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellPropertyType.BORDER_RIGHT));
+ }
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.TOP);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.BOTTOM);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.LEFT);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.RIGHT);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.INSIDE_HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ } else if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ } else {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE_HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_TOP));
+ } else if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_BOTTOM));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.INSIDE_VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ } else {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE_VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellPropertyType.BORDER_LEFT));
+ } else if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellPropertyType.BORDER_RIGHT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ }
+
+ @Test
+ void drawBorders() throws IOException {
+ CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
+ PropertyTemplate pt = new PropertyTemplate();
+ pt.drawBorders(a1c3, BorderStyle.THIN,
+ BorderExtent.ALL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ if (i == 0) {
+ if (j == 0) {
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ }
+ } else if (i == 2) {
+ if (j == 0) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ }
+ } else {
+ if (j == 0) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_BOTTOM));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.THIN,
+ pt.getBorderStyle(i, j,
+ CellUtil.BORDER_RIGHT));
+ }
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.TOP);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.BOTTOM);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.LEFT);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.RIGHT);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.INSIDE_HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ } else if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ } else {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE_HORIZONTAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (i == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ } else if (i == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.INSIDE_VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ } else if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ } else {
+ assertEquals(2, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ }
+ }
+ }
+ pt.drawBorders(a1c3, BorderStyle.NONE,
+ BorderExtent.NONE);
+ pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ BorderExtent.OUTSIDE_VERTICAL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ if (j == 0) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM,
+ pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ } else if (j == 2) {
+ assertEquals(1, pt.getNumBorders(i, j));
+ assertEquals(BorderStyle.MEDIUM, pt
+ .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ } else {
+ assertEquals(0, pt.getNumBorders(i, j));
+ }
+ }
+ }
+ }
+
+ @Test
+ void drawBorderColorsByEnum() throws IOException {
+ CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
+ PropertyTemplate pt = new PropertyTemplate();
+ pt.drawBorderColors(a1c3, IndexedColors.RED.getIndex(),
+ BorderExtent.ALL);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ assertEquals(4, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.RED.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ }
+ }
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
+ BorderExtent.OUTSIDE);
+ for (int i = 0; i <= 2; i++) {
+ for (int j = 0; j <= 2; j++) {
+ assertEquals(4, pt.getNumBorders(i, j));
+ assertEquals(4, pt.getNumBorderColors(i, j));
+ if (i == 0) {
+ if (j == 0) {
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ } else if (j == 2) {
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ } else {
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ }
+ } else if (i == 2) {
+ if (j == 0) {
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ } else if (j == 2) {
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
+ } else {
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
}
} else {
if (j == 0) {
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else if (j == 2) {
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else {
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_BOTTOM));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.THIN,
- pt.getBorderStyle(i, j,
- CellUtil.BORDER_RIGHT));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.RED.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
}
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.TOP);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.BOTTOM);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.LEFT);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.RIGHT);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.HORIZONTAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(2, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(2, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.INSIDE_HORIZONTAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
} else if (i == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
} else {
assertEquals(2, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(2, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.OUTSIDE_HORIZONTAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (i == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_TOP));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.TOP_BORDER_COLOR));
} else if (i == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_BOTTOM));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.BOTTOM_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.VERTICAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
assertEquals(2, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(2, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(), pt
+ .getTemplateProperty(i, j, CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.INSIDE_VERTICAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else if (j == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
} else {
assertEquals(2, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(2, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
}
}
}
pt.drawBorders(a1c3, BorderStyle.NONE,
BorderExtent.NONE);
- pt.drawBorders(a1c3, BorderStyle.MEDIUM,
+ pt.drawBorderColors(a1c3, IndexedColors.AUTOMATIC.getIndex(),
+ BorderExtent.NONE);
+ pt.drawBorderColors(a1c3, IndexedColors.BLUE.getIndex(),
BorderExtent.OUTSIDE_VERTICAL);
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 2; j++) {
if (j == 0) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM,
- pt.getBorderStyle(i, j, CellUtil.BORDER_LEFT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.LEFT_BORDER_COLOR));
} else if (j == 2) {
assertEquals(1, pt.getNumBorders(i, j));
- assertEquals(BorderStyle.MEDIUM, pt
- .getBorderStyle(i, j, CellUtil.BORDER_RIGHT));
+ assertEquals(1, pt.getNumBorderColors(i, j));
+ assertEquals(IndexedColors.BLUE.getIndex(),
+ pt.getTemplateProperty(i, j,
+ CellPropertyType.RIGHT_BORDER_COLOR));
} else {
assertEquals(0, pt.getNumBorders(i, j));
+ assertEquals(0, pt.getNumBorderColors(i, j));
}
}
}
}
}
+ @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);
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());
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());
}
}
}
- 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();