Bug 48779 - XSSFCellStyle.getFillForegroundColor dosn't return the right value
Summary: XSSFCellStyle.getFillForegroundColor dosn't return the right value
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.6-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2010-02-19 15:04 UTC by Andrej
Modified: 2010-05-26 13:48 UTC (History)
0 users

test file (7.73 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2010-02-19 15:05 UTC, Andrej

Note You need to log in before you can comment on or make changes to this bug.
Description Andrej 2010-02-19 15:04:24 UTC
If you try to get a color from a cell which has a non-empty color, you always get black color independently of what is the right color of the cell. This bug can be reproduced only for Excel 2007 formats. For '.xls' files it's not reproducible. 

So if you run the following code for the attached files:
	public static void main(String[] args) {
		Workbook workbook = null;
		try {
			workbook = new XSSFWorkbook("C:/Test.xlsx");
			System.out.println("Cell color in Excel 2007: " + 
		} catch (IOException e) {

		try {
			workbook = new HSSFWorkbook(new FileInputStream("C:/Test.xls"));
			System.out.println("Cell color in Excel 2003: " + 
		} catch (IOException e) {

you will see the following output:
Cell color in Excel 2007: 0
Cell color in Excel 2003: 10

Comment 1 Andrej 2010-02-19 15:05:28 UTC
Created attachment 25024 [details]
test file
Comment 2 Nick Burch 2010-05-26 13:48:22 UTC
The problem is that XSSF does some colours differently to HSSF. HSSF only ever had indexed colours, while XSSF has a mixture of indexed colours and inline defined colours

I'd suggest you try the new getFillForegroundColorColor() and getFillBackgroundColorColor() methods on a CellStyle, which'll always get you the underlying Color object no matter if they're inline or indexed

Please give feedback on the mailing list about the new ss.usermodel.Color class, as at the moment it's a stub, but if we can decide what's generic between XSSFColor and HSSFColor we can add in methods to it

(You'll need a svn checkout of r948511 of later)