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 12:22:54 UTC
svn commit: r1902630 - 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 12:22:54 2022
New Revision: 1902630
URL: http://svn.apache.org/viewvc?rev=1902630&view=rev
Log:
add param that allows invalid colors to be ignored
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=1902630&r1=1902629&r2=1902630&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 12:22:54 2022
@@ -832,15 +832,17 @@ 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
+ * @param color org.apache.poi.ss.usermodel.Color to set
+ * @param ignoreInvalidColors when set to true, the method will ignore issues like trying to set a
+ * HSSFColor on a XSSFCellStyle
* @throws IllegalArgumentException if you provide a <code>Color</code> instance that is not a {@link XSSFColor}
* @since POI 5.2.3
*/
@Override
- public void setFillBackgroundColor(org.apache.poi.ss.usermodel.Color color) {
+ public void setFillBackgroundColor(org.apache.poi.ss.usermodel.Color color, boolean ignoreInvalidColors) {
if (color == null || color instanceof XSSFColor) {
setFillBackgroundColor((XSSFColor)color);
- } else {
+ } else if (!ignoreInvalidColors) {
throw new IllegalArgumentException("XSSFCellStyle only accepts XSSFColor instances");
}
}
@@ -903,14 +905,16 @@ public class XSSFCellStyle implements Ce
* Set the foreground fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
* <br>
* @param color the color to use
+ * @param ignoreInvalidColors when set to true, the method will ignore issues like trying to set a
+ * HSSFColor on a XSSFCellStyle
* @throws IllegalArgumentException if you provide a <code>Color</code> instance that is not a {@link XSSFColor}
* @since POI 5.2.3
*/
@Override
- public void setFillForegroundColor(org.apache.poi.ss.usermodel.Color color) {
+ public void setFillForegroundColor(org.apache.poi.ss.usermodel.Color color, boolean ignoreInvalidColors) {
if (color == null || color instanceof XSSFColor) {
setFillForegroundColor((XSSFColor)color);
- } else {
+ } else if (!ignoreInvalidColors) {
throw new IllegalArgumentException("XSSFCellStyle only accepts XSSFColor instances");
}
}
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=1902630&r1=1902629&r2=1902630&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 12:22:54 2022
@@ -642,16 +642,18 @@ public final class HSSFCellStyle impleme
* Set the background fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
* <br>
* @param color the color to use
+ * @param ignoreInvalidColors when set to true, the method will ignore issues like trying to set a
+ * HSSFColor on a XSSFCellStyle
* @throws IllegalArgumentException if you provide a <code>Color</code> instance that is not a {@link HSSFColor}
* @since POI 5.2.3
*/
@Override
- public void setFillBackgroundColor(org.apache.poi.ss.usermodel.Color color)
+ public void setFillBackgroundColor(org.apache.poi.ss.usermodel.Color color, boolean ignoreInvalidColors)
{
if (color instanceof HSSFColor) {
short index2 = ((HSSFColor)color).getIndex2();
if (index2 != -1) setFillBackgroundColor(index2);
- } else if (color != null) {
+ } else if (color != null && !ignoreInvalidColors) {
throw new IllegalArgumentException("HSSFCellStyle only accepts HSSFColor instances");
}
}
@@ -701,16 +703,18 @@ public final class HSSFCellStyle impleme
* Set the foreground fill color represented as a {@link org.apache.poi.ss.usermodel.Color} value.
* <br>
* @param color the color to use
+ * @param ignoreInvalidColors when set to true, the method will ignore issues like trying to set a
+ * HSSFColor on a XSSFCellStyle
* @throws IllegalArgumentException if you provide a <code>Color</code> instance that is not a {@link HSSFColor}
* @since POI 5.2.3
*/
@Override
- public void setFillForegroundColor(org.apache.poi.ss.usermodel.Color color)
+ public void setFillForegroundColor(org.apache.poi.ss.usermodel.Color color, boolean ignoreInvalidColors)
{
if (color instanceof HSSFColor) {
short index2 = ((HSSFColor)color).getIndex2();
if (index2 != -1) setFillForegroundColor(index2);
- } else if (color != null) {
+ } else if (color != null && !ignoreInvalidColors) {
throw new IllegalArgumentException("HSSFCellStyle only accepts HSSFColor instances");
}
}
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=1902630&r1=1902629&r2=1902630&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 12:22:54 2022
@@ -312,13 +312,26 @@ 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)
+ * Set the background fill color.
+ * Uses a {@link org.apache.poi.ss.usermodel.Color} instead of an indexed color.
*
* @param color org.apache.poi.ss.usermodel.Color to set
* @since POI 5.2.3
*/
- void setFillBackgroundColor(Color color);
+ default void setFillBackgroundColor(Color color) {
+ setFillBackgroundColor(color, false);
+ }
+
+ /**
+ * Set the background fill color.
+ * Uses a {@link org.apache.poi.ss.usermodel.Color} instead of an indexed color.
+ *
+ * @param color org.apache.poi.ss.usermodel.Color to set
+ * @param ignoreInvalidColors when set to true, the method will ignore issues like trying to set a
+ * HSSFColor on a XSSFCellStyle
+ * @since POI 5.2.3
+ */
+ void setFillBackgroundColor(Color color, boolean ignoreInvalidColors);
/**
* get the background fill color, if the fill
@@ -344,13 +357,26 @@ 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)
+ * Set the foreground fill color.
+ * Uses a {@link org.apache.poi.ss.usermodel.Color} instead of an indexed color.
+ *
+ * @param color org.apache.poi.ss.usermodel.Color to set
+ * @since POI 5.2.3
+ */
+ default void setFillForegroundColor(Color color) {
+ setFillForegroundColor(color, false);
+ }
+
+ /**
+ * Set the foreground fill color.
+ * Uses a {@link org.apache.poi.ss.usermodel.Color} instead of an indexed color.
*
* @param color org.apache.poi.ss.usermodel.Color to set
+ * @param ignoreInvalidColors when set to true, the method will ignore issues like trying to set a
+ * HSSFColor on a XSSFCellStyle
* @since POI 5.2.3
*/
- void setFillForegroundColor(Color color);
+ void setFillForegroundColor(Color color, boolean ignoreInvalidColors);
/**
* get the foreground fill color, if the fill
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=1902630&r1=1902629&r2=1902630&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 12:22:54 2022
@@ -532,8 +532,8 @@ public final class CellUtil {
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.setFillForegroundColor(getColor(properties, FILL_FOREGROUND_COLOR_COLOR), true);
+ style.setFillBackgroundColor(getColor(properties, FILL_BACKGROUND_COLOR_COLOR), true);
style.setFont(workbook.getFontAt(getInt(properties, FONT)));
style.setHidden(getBoolean(properties, HIDDEN));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org