使用Apache POI在条件格式中自定义背景颜色

时间:2023-01-31 20:23:34

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:

我有一个XSSF工作簿,我想在一组已定义了条件格式的单元格中定义一个自定义的背景色,但是问题是PatternFormatting类中的setFillBackgroundColor()方法只接受一个类型短的参数,而不是像这样的XSSFColor:

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

我可以使用fill.setFillBackgroundColor(IndexedColors.RED.index),但我想定义一个自定义颜色。我该怎么做呢?

1 个解决方案

#1


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:

对于那些仍在阅读本文并在2014年遇到请求者描述的问题的人来说,您可能正在使用Apache POI版本,在3.13之前。试着升级到至少3.13,你确实应该能够做到:

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

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

(参见:https://bz.apache.org/bugzilla/show_bug.cgi?id=56774)

#1


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:

对于那些仍在阅读本文并在2014年遇到请求者描述的问题的人来说,您可能正在使用Apache POI版本,在3.13之前。试着升级到至少3.13,你确实应该能够做到:

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

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

(参见:https://bz.apache.org/bugzilla/show_bug.cgi?id=56774)