2

I had a HSSF workbook with my custom colors in it but now it turns out I need to use XSSF to create xslx files.

I have changed everything accordingly but the only thing that has me stumped is how to use a custom made XSSFColor in something like this :

XSSFPatternFormatting YesForm = YesRule.createPatternFormatting(); YesForm.setFillBackgroundColor(IndexedColors.GREEN.getIndex());

This worked fine when I had my custom pallet but xssf doesn't seem to have anything similar or am I mistaken?

Thank you in advance.

Pod
  • 31
  • 1
  • 7

2 Answers2

2

I've been trying to find this out as well, and from what I can tell, it may not be possible.

Here's a reported bug on this topic:

http://mail-archives.apache.org/mod_mbox/poi-dev/201407.mbox/%3Cbug-56774-47293@https.issues.apache.org/bugzilla/%3E

The currently suggested answer by wobblycogs does not address the original question, as it is not related to Conditional Formatting (setting a color on an individual cell is easy enough to do, but not that's not the OP's question).

-1

I think probably what you want is something like this:

XSSFCellStyle style1 = wb.createCellStyle();
style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128)));
style1.setFillPattern(CellStyle.SOLID_FOREGROUND);
cell.setCellStyle(style1);

Just define your styles upfront and then paint any cells you want with them. I'm most familiar with HSSF generation but I've used this a couple of times with XSSF and it works well.

wobblycogs
  • 4,083
  • 7
  • 37
  • 48