aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-07-10 18:46:54 +0000
committerPJ Fanning <fanningpj@apache.org>2022-07-10 18:46:54 +0000
commit44930ebfa0bc1a1bcde07022a6b8f745a3b05227 (patch)
treedb4e2e1840b309f4f46b99dacebfa99909116a0b
parent5386fe171d05e2af97c2e80c3e4a2a04d548a863 (diff)
downloadpoi-44930ebfa0bc1a1bcde07022a6b8f745a3b05227.tar.gz
poi-44930ebfa0bc1a1bcde07022a6b8f745a3b05227.zip
[bug-66052] add test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902637 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/TestSSUtilVsXSSFColor.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestSSUtilVsXSSFColor.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestSSUtilVsXSSFColor.java
new file mode 100644
index 0000000000..7ddc769486
--- /dev/null
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestSSUtilVsXSSFColor.java
@@ -0,0 +1,66 @@
+package org.apache.poi.xssf;
+
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.PropertyTemplate;
+import org.apache.poi.xssf.usermodel.*;
+import org.apache.commons.codec.binary.Hex;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class TestSSUtilVsXSSFColor {
+
+ @Test
+ void testXSSFCellStyle() throws Exception {
+
+ try (
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+ ) {
+ XSSFCellStyle cellStyle = workbook.createCellStyle();
+ final String rgbS = "ffff00";
+ final byte[] rgbB = Hex.decodeHex(rgbS);
+ IndexedColorMap colorMap = workbook.getStylesSource().getIndexedColors();
+ XSSFColor color = new XSSFColor(rgbB, colorMap);
+ cellStyle.setFillForegroundColor(color);
+ cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+
+ final int startDataRow = 6; // row 7 (index 0-based)
+ final int endDataRow = 11; // row 12 (index 0-based)
+ final int startDataColumn = 1; // column B (index 0-based)
+ final int endDataColumn = 10; // column K (index 0-based)
+
+ Sheet sheet = workbook.createSheet();
+
+ for (int r = startDataRow; r <= endDataRow; r++) {
+ Row row = sheet.createRow(r);
+ for (int c = startDataColumn; c <= endDataColumn; c++) {
+ Cell cell = row.createCell(c);
+ cell.setCellValue(cell.getAddress().formatAsString());
+ cell.setCellStyle(cellStyle);
+ }
+ }
+
+ PropertyTemplate propertyTemplate = new PropertyTemplate();
+ propertyTemplate.drawBorders(new CellRangeAddress(startDataRow, endDataRow, startDataColumn, endDataColumn),
+ BorderStyle.MEDIUM, BorderExtent.ALL);
+
+ propertyTemplate.applyBorders(sheet); // after this all cell interiors are filled black, because IndexedColors 0 is set
+ // same is using all other org.apache.poi.ss.util classes which manipulate cell styles (CellUtil or RegionUtil)
+
+ workbook.write(bos);
+
+ try(XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) {
+ XSSFSheet sheetWb2 = wb2.getSheetAt(0);
+ XSSFCell testCell = sheetWb2.getRow(startDataRow).getCell(startDataColumn);
+ XSSFCellStyle testStyle = testCell.getCellStyle();
+ XSSFColor testColor = testStyle.getFillForegroundXSSFColor();
+ assertFalse(testColor.isIndexed());
+ assertEquals(rgbS, Hex.encodeHexString(testColor.getRGB()));
+ }
+ }
+ }
+} \ No newline at end of file