You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Andreas Reichel <an...@manticore-projects.com> on 2015/02/22 07:40:26 UTC

Fun with XSSF Fill Colors

Dear All.

I built a java table component, which actually represents MS Excel files
(as per HSSF or XSSF flavor).
Unfortunately I spent hours for fiddeling around with simple cell
background colors, as a simple

XSSFCell xssfCell = (XSSFCell) cell;
XSSFCellStyle xssfCellStyle = xssfCell.getCellStyle();
XSSFColor fillForegroundColorColor =
xssfCellStyle.getFillForegroundColorColor();

always returns NULL (while the actual color is #FF030146).

I finally ended up with a construct like this:

XSSFCell xssfCell = (XSSFCell) cell;
XSSFCellStyle xssfCellStyle = xssfCell.getCellStyle();

XSSFColor fillForegroundColorColor =
xssfCellStyle.getFillForegroundColorColor();
if (fillForegroundColorColor == null) {
	// nasty long to short translation needed!
        short fillId = (short) xssfCellStyle.getCoreXf().getFillId(); 
        XSSFCellFill fill = ((XSSFWorkbook)
workbook).getStylesSource().getFillAt(fillId);
        fillForegroundColorColor = fill.getFillForegroundColor();
}

which gives me indeed the correct ARGB code #FF030146.
Now I have two main questions:

1) Is it a bug or a feature? Why can't
xssfCellStyle.getFillForegroundColorColor() just return the right color?
2) Is the approach correct and robust? Any exceptions or use cases, when
it will break? It is actually difficult to find any documentation on
that matter.

Your kind help will be much appreciated. Best regards
Andreas



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org