From 3092c1121e7d438ffe577152ccd4909ce03cbbc4 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Fri, 8 Jul 2016 18:45:15 +0000 Subject: [PATCH] bug 55555: set fill pattern, foreground color, and background color order correctly to follow HSSFCellStyle's order requirement; patch from Qualtagh. This closes #33 on Github git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751955 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/ss/util/CellUtil.java | 8 +++---- .../apache/poi/ss/util/BaseTestCellUtil.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java index 5963e7d7d..4f8c9cd18 100644 --- a/src/java/org/apache/poi/ss/util/CellUtil.java +++ b/src/java/org/apache/poi/ss/util/CellUtil.java @@ -331,9 +331,9 @@ public final class CellUtil { putBorderStyle(properties, BORDER_TOP, style.getBorderTop()); putShort(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor()); putShort(properties, DATA_FORMAT, style.getDataFormat()); - putShort(properties, FILL_BACKGROUND_COLOR, style.getFillBackgroundColor()); - putShort(properties, FILL_FOREGROUND_COLOR, style.getFillForegroundColor()); putShort(properties, FILL_PATTERN, style.getFillPattern()); + putShort(properties, FILL_FOREGROUND_COLOR, style.getFillForegroundColor()); + putShort(properties, FILL_BACKGROUND_COLOR, style.getFillBackgroundColor()); putShort(properties, FONT, style.getFontIndex()); putBoolean(properties, HIDDEN, style.getHidden()); putShort(properties, INDENTION, style.getIndention()); @@ -363,9 +363,9 @@ public final class CellUtil { style.setBorderTop(getBorderStyle(properties, BORDER_TOP)); style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR)); style.setDataFormat(getShort(properties, DATA_FORMAT)); - style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR)); - style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR)); style.setFillPattern(getShort(properties, FILL_PATTERN)); + style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR)); + style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR)); style.setFont(workbook.getFontAt(getShort(properties, FONT))); style.setHidden(getBoolean(properties, HIDDEN)); style.setIndention(getShort(properties, INDENTION)); diff --git a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java index 59609bfbe..5caf980b0 100644 --- a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java +++ b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java @@ -31,7 +31,9 @@ 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.IndexedColors; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; @@ -260,4 +262,23 @@ public class BaseTestCellUtil { wb2.close(); } } + + // bug 55555 + @Test + public void setFillForegroundColorBeforeFillBackgroundColor() { + Workbook wb1 = _testDataProvider.createWorkbook(); + Cell A1 = wb1.createSheet().createRow(0).createCell(0); + Map properties = new HashMap(); + // FIXME: Use FillPatternType.BRICKS enum + properties.put(CellUtil.FILL_PATTERN, CellStyle.BRICKS); + properties.put(CellUtil.FILL_FOREGROUND_COLOR, IndexedColors.BLUE.index); + properties.put(CellUtil.FILL_BACKGROUND_COLOR, IndexedColors.RED.index); + + CellUtil.setCellStyleProperties(A1, properties); + CellStyle style = A1.getCellStyle(); + // FIXME: Use FillPatternType.BRICKS enum + assertEquals("fill pattern", CellStyle.BRICKS, style.getFillPattern()); + assertEquals("fill foreground color", IndexedColors.BLUE, IndexedColors.fromInt(style.getFillForegroundColor())); + assertEquals("fill background color", IndexedColors.RED, IndexedColors.fromInt(style.getFillBackgroundColor())); + } }