You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/07/10 10:12:20 UTC

svn commit: r1902622 - in /poi/trunk: poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/ poi/src/main/java/org/apache/poi/hssf/usermodel/ poi/src/main/java/org/apache/poi/ss/usermodel/ poi/src/main/java/org/apache/poi/ss/util/

Author: fanningpj
Date: Sun Jul 10 10:12:20 2022
New Revision: 1902622

URL: http://svn.apache.org/viewvc?rev=1902622&view=rev
Log:
[bug-66052] apply cell style fixes supplied by Axel Richter

Modified:
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
    poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
    poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/CellStyle.java
    poi/trunk/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=1902622&r1=1902621&r2=1902622&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java Sun Jul 10 10:12:20 2022
@@ -830,6 +830,19 @@ public class XSSFCellStyle implements Ce
     }
 
     /**
+     * Set the background fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
+     * <br>
+     * @param color the color to use
+     * @since POI 5.2.3
+     */
+    @Override
+    public void setFillBackgroundColor(org.apache.poi.ss.usermodel.Color color) {
+        if (color instanceof XSSFColor) {
+            setFillBackgroundColor((XSSFColor)color);
+        }
+    }
+    
+    /**
      * Set the background fill color represented as a indexed color value.
      * <p>
      * For example:
@@ -882,6 +895,19 @@ public class XSSFCellStyle implements Ce
 
         addFill(ct);
     }
+ 
+    /**
+     * Set the foreground fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
+     * <br>
+     * @param color the color to use
+     * @since POI 5.2.3
+     */
+    @Override
+    public void setFillForegroundColor(org.apache.poi.ss.usermodel.Color color) {
+        if (color instanceof XSSFColor) {
+            setFillForegroundColor((XSSFColor)color);
+        }
+    }
 
     /**
      * Set the foreground fill color as a indexed color value

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java?rev=1902622&r1=1902621&r2=1902622&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java Sun Jul 10 10:12:20 2022
@@ -637,6 +637,21 @@ public final class HSSFCellStyle impleme
         _format.setFillBackground(bg);
         checkDefaultBackgroundFills();
     }
+    
+    /**
+     * Set the background fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
+     * <br>
+     * @param color the color to use
+     * @since POI 5.2.3
+     */
+    @Override
+    public void setFillBackgroundColor(org.apache.poi.ss.usermodel.Color color)
+    {
+        if (color instanceof HSSFColor) {
+            short index2 = ((HSSFColor)color).getIndex2();
+            if (index2 != -1) setFillBackgroundColor(index2);
+        }
+    }
 
     /**
      * Get the background fill color.
@@ -678,6 +693,21 @@ public final class HSSFCellStyle impleme
         _format.setFillForeground(bg);
         checkDefaultBackgroundFills();
     }
+    
+    /**
+     * Set the foreground fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
+     * <br>
+     * @param color the color to use
+     * @since POI 5.2.3
+     */
+    @Override
+    public void setFillForegroundColor(org.apache.poi.ss.usermodel.Color color)
+    {
+        if (color instanceof HSSFColor) {
+            short index2 = ((HSSFColor)color).getIndex2();
+            if (index2 != -1) setFillForegroundColor(index2);
+        }
+    }
 
     /**
      * Get the foreground fill color.

Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/CellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/CellStyle.java?rev=1902622&r1=1902621&r2=1902622&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/CellStyle.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/CellStyle.java Sun Jul 10 10:12:20 2022
@@ -312,6 +312,15 @@ public interface CellStyle {
     void setFillBackgroundColor(short bg);
 
     /**
+     * set the background fill color.
+     * use not a indexed color but a {@link org.apache.poi.ss.usermodel.Color)
+     *
+     * @param color org.apache.poi.ss.usermodel.Color to set
+     * @since POI 5.2.3
+     */
+    void setFillBackgroundColor(Color color);
+
+    /**
      * get the background fill color, if the fill
      *  is defined with an indexed color.
      * @return fill color index, or 0 if not indexed (XSSF only)
@@ -335,6 +344,15 @@ public interface CellStyle {
     void setFillForegroundColor(short bg);
 
     /**
+     * set the foreground fill color.
+     * use not a indexed color but a {@link org.apache.poi.ss.usermodel.Color)
+     *
+     * @param color org.apache.poi.ss.usermodel.Color to set
+     * @since POI 5.2.3
+     */
+    void setFillForegroundColor(Color color);
+
+    /**
      * get the foreground fill color, if the fill  
      *  is defined with an indexed color.
      * @return fill color, or 0 if not indexed (XSSF only)

Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java?rev=1902622&r1=1902621&r2=1902622&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java Sun Jul 10 10:12:20 2022
@@ -56,6 +56,10 @@ public final class CellUtil {
     public static final String DATA_FORMAT = "dataFormat";
     public static final String FILL_BACKGROUND_COLOR = "fillBackgroundColor";
     public static final String FILL_FOREGROUND_COLOR = "fillForegroundColor";
+    
+    public static final String FILL_BACKGROUND_COLOR_COLOR = "fillBackgroundColorColor";
+    public static final String FILL_FOREGROUND_COLOR_COLOR = "fillForegroundColorColor";
+
     public static final String FILL_PATTERN = "fillPattern";
     public static final String FONT = "font";
     public static final String HIDDEN = "hidden";
@@ -79,6 +83,13 @@ public final class CellUtil {
                     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
@@ -376,6 +387,7 @@ public final class CellUtil {
     public static void setCellStyleProperties(Cell cell, Map<String, Object> properties) {
         Workbook workbook = cell.getSheet().getWorkbook();
         CellStyle originalStyle = cell.getCellStyle();
+        
         CellStyle newStyle = null;
         Map<String, Object> values = getFormatProperties(originalStyle);
         putAll(properties, values);
@@ -447,8 +459,12 @@ public final class CellUtil {
         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());
@@ -475,6 +491,8 @@ public final class CellUtil {
         for (final String key : src.keySet()) {
             if (shortValues.contains(key)) {
                 dest.put(key, getShort(src, key));
+            } else if (colorValues.contains(key)) {
+                dest.put(key, getColor(src, key));
             } else if (intValues.contains(key)) {
                 dest.put(key, getInt(src, key));
             } else if (booleanValues.contains(key)) {
@@ -511,8 +529,12 @@ 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));
+        style.setFillBackgroundColor(getColor(properties, FILL_BACKGROUND_COLOR_COLOR));
+
         style.setFont(workbook.getFontAt(getInt(properties, FONT)));
         style.setHidden(getBoolean(properties, HIDDEN));
         style.setIndention(getShort(properties, INDENTION));
@@ -541,6 +563,23 @@ public final class CellUtil {
         }
         return 0;
     }
+    
+    /**
+     * Utility method that returns the named Color value from the given map.
+     *
+     * @param properties map of named properties (String -> Object)
+     * @param name property name
+     * @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);
+        if (value instanceof Color) {
+            return (Color) value;
+        }
+        return null;
+    }
+
 
     /**
      * Utility method that returns the named int value from the given map.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org