Hi, I did a fix lately under bug 56295 - https://bz.apache.org/bugzilla/show_bug.cgi?id=56295, POI previously did use a default of "false" for the "applyfill" attribute, whereas Excel and LibreOffice seem to use "true" as default. As a result of this, POI did not read in background/foreground fill colors correctly in these cases. The Spec unfortunately seems to not mandate a default value.
I think your problem pretty well matches what my change will fix! We now switched the default to "true" so that such spreadsheets are handled the same way as Excel does and as result XSSFCellStyle.getFillForegroundColorColor() now returns values where it previously might have returned null. Please give it a try, the changes are not included in 3.12-beta1 so you will need to grab latest from trunk or use a recent trunk-build from https://builds.apache.org/view/POI/job/POI/lastSuccessfulBuild/artifact/build/dist/ Dominik. On Tue, Mar 3, 2015 at 1:13 PM, Andreas Reichel <[email protected]> wrote: > 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: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
