diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-07-10 13:54:09 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-07-10 13:54:09 +0000 |
commit | e0ca0baebf7d9741b47dd67570ef755f8775bc0b (patch) | |
tree | 87012189902f24b26236956f071713d2e01dc933 /poi | |
parent | ec3e9218ef8c6991f8a969830ac0ed6f0e2e878b (diff) | |
download | poi-e0ca0baebf7d9741b47dd67570ef755f8775bc0b.tar.gz poi-e0ca0baebf7d9741b47dd67570ef755f8775bc0b.zip |
try to fix tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902633 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r-- | poi/src/main/java/org/apache/poi/ss/util/CellUtil.java | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java b/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java index 8bab37d4da..bc47b10da0 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java +++ b/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java @@ -401,7 +401,7 @@ public final class CellUtil { Map<String, Object> wbStyleMap = getFormatProperties(wbStyle); // the desired style already exists in the workbook. Use the existing style. - if (wbStyleMap.equals(values)) { + if (styleMapsMatch(wbStyleMap, values)) { newStyle = wbStyle; break; } @@ -416,6 +416,21 @@ public final class CellUtil { cell.setCellStyle(newStyle); } + private static boolean styleMapsMatch(final Map<String, Object> map1, final Map<String, Object> map2) { + final Map<String, Object> map1Copy = new HashMap<>(map1); + final Map<String, Object> map2Copy = new HashMap<>(map2); + 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); + if (map1Copy.equals(map2Copy)) { + final boolean backColorsMatch = backColor1 == null || backColor2 == null || backColor1.equals(backColor2); + final boolean foreColorsMatch = foreColor1 == null || foreColor2 == null || foreColor1.equals(foreColor2); + return backColorsMatch && foreColorsMatch; + } + return false; + } + /** * <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 @@ -529,11 +544,27 @@ public final class CellUtil { style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR)); style.setDataFormat(getShort(properties, DATA_FORMAT)); style.setFillPattern(getFillPattern(properties, FILL_PATTERN)); - - style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR)); - style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR)); - style.setFillForegroundColor(getColor(properties, FILL_FOREGROUND_COLOR_COLOR), true); - style.setFillBackgroundColor(getColor(properties, FILL_BACKGROUND_COLOR_COLOR), true); + + Color foregroundFillColor = getColor(properties, FILL_FOREGROUND_COLOR_COLOR); + Color backgroundFillColor = getColor(properties, FILL_BACKGROUND_COLOR_COLOR); + if (foregroundFillColor != null) { + try { + style.setFillForegroundColor(foregroundFillColor); + } catch (IllegalArgumentException iae) { + style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR)); + } + } else { + style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR)); + } + if (backgroundFillColor != null) { + try { + style.setFillBackgroundColor(backgroundFillColor); + } catch (IllegalArgumentException iae) { + style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR)); + } + } else { + style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR)); + } style.setFont(workbook.getFontAt(getInt(properties, FONT))); style.setHidden(getBoolean(properties, HIDDEN)); |