4

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?.

Tiny
  • 27,221
  • 105
  • 339
  • 599
edkalel
  • 415
  • 2
  • 5
  • 12
  • 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 Nov 05 '14 at 07:27
  • @Angga The problem is the `setFillBackgroundColor()` method in the `PatternFormatting` class only accepts a type short argument, not a `XSSFColor`. – edkalel Nov 05 '14 at 21:32
  • related: http://stackoverflow.com/questions/10912578/apache-poi-xssfcolor-from-hex-code – Maxwell Cheng Mar 24 '17 at 03:08

1 Answers1

0

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)

stijnh
  • 89
  • 4