/**
* 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");
}
}
* 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");
}
}
* 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");
}
}
* 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");
}
}
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
+ */
+ 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);
+ void setFillBackgroundColor(Color color, boolean ignoreInvalidColors);
/**
* get the background fill color, if the fill
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
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));