From 5c964e419438ad8f1aaf12dd2a05541d23580d20 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 7 Jan 2023 22:24:49 +0000 Subject: [PATCH] [bug-66413] try to fix HSSF code where you can set fill colors git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1906451 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java | 8 ++++---- poi/src/main/java/org/apache/poi/ss/util/CellUtil.java | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java index 55621d9095..2dfaca3920 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java @@ -649,8 +649,8 @@ public final class HSSFCellStyle implements CellStyle, Duplicatable { public void setFillBackgroundColor(org.apache.poi.ss.usermodel.Color color) { if (color instanceof HSSFColor) { - short index2 = ((HSSFColor)color).getIndex2(); - if (index2 != -1) setFillBackgroundColor(index2); + final short index = ((HSSFColor)color).getIndex(); + if (index != -1) setFillBackgroundColor(index); } else if (color != null) { throw new IllegalArgumentException("HSSFCellStyle only accepts HSSFColor instances"); } @@ -708,8 +708,8 @@ public final class HSSFCellStyle implements CellStyle, Duplicatable { public void setFillForegroundColor(org.apache.poi.ss.usermodel.Color color) { if (color instanceof HSSFColor) { - short index2 = ((HSSFColor)color).getIndex2(); - if (index2 != -1) setFillForegroundColor(index2); + final short index = ((HSSFColor)color).getIndex(); + if (index != -1) setFillForegroundColor(index); } else if (color != null) { throw new IllegalArgumentException("HSSFCellStyle only accepts HSSFColor instances"); } 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 43f2be2600..3f1a30ac81 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 @@ -398,9 +398,15 @@ public final class CellUtil { if (properties.containsKey(FILL_FOREGROUND_COLOR_COLOR) && properties.get(FILL_FOREGROUND_COLOR_COLOR) == null) { values.remove(FILL_FOREGROUND_COLOR); } + if (properties.containsKey(FILL_FOREGROUND_COLOR) && !properties.containsKey(FILL_FOREGROUND_COLOR_COLOR)) { + values.remove(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(FILL_BACKGROUND_COLOR) && !properties.containsKey(FILL_BACKGROUND_COLOR_COLOR)) { + values.remove(FILL_BACKGROUND_COLOR_COLOR); + } putAll(properties, values); // index seems like what index the cellstyle is in the list of styles for a workbook. -- 2.39.5