4
votes

I have a XSSF workbook and I want to define a custom background color in a set of cells with a conditional formatting defined, but the problem is that the setFillBackgroundColor() method in the PatternFormatting class only accepts a type short argument, not a XSSFColor like this:

PatternFormatting fill = rule1.createPatternFormatting();
fill.setFillBackgroundColor(new XSSFColor(new java.awt.Color(80, 80, 100));
fill.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

I can do fill.setFillBackgroundColor(IndexedColors.RED.index), but I want to define a custom color. How can i do this?.

1
that fill.setFillBackgroundColor(new XSSFColor(new java.awt.Color(80, 80, 100)); is custom R=80 G=80 B=100 right? what is the problem by using that? - Angga
@Angga The problem is the setFillBackgroundColor() method in the PatternFormatting class only accepts a type short argument, not a XSSFColor. - edkalel

1 Answers

0
votes

For anyone still reading this and having the problem the requester describes back in 2014, you are probably on a version of Apache POI before 3.13. Try upgrading to at least 3.13 where you should indeed be able to do:

fill.setFillBackgroundColor(new XSSFColor(new java.awt.Color(80, 80, 100))

(see also here: https://bz.apache.org/bugzilla/show_bug.cgi?id=56774)