开发者

Apache POI - background colours not as expected

Thanks for looking.

Im using Apache POI to read an excel file. I want to use conditional logic that will use background colour. But I don't understand the results Im getting.

Why does following code show different results for same colours?

Code:

XSSFCell cell = (XSSFCell) row.getCell(i);     
if(cell.getDateCellValue()!=null) {
  DateTime val = new DateTime(cell.getDateCellValue()); //Joda-Time lib.

  XSSFCellStyle cellStyle = (XSSFCellStyle) cell.getCellStyle().clone();
  cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
  XSSFColor x = cellStyle.getFillForegroundXSSFColor();

  String colorStrVal =  x==null ? "null" : x.getARGBHex() + ":" + x.getIndexed();
  System.out.println(val.toString("dd/MM/yyyy") + " - " + colorStrVal);
}

Results - I expect non-specified colour entries to all be same (they are grey and look fine in excel - all register as same colour):

06/04/2007 - FFFFFFFF:0
02/06/2008 - FFFFFFFF:0
10/05/2011 - FFFFF2B9:0 //yellow
26/07/2008 - FFFFFFFF:0
04/07/2010 - FFFFFFFF:0
12/04/2009 - FFFFFFFF:0
19/09/2010 - FFFFFFFF:0
16/04/2011 - FFFFFFFF:0
16/01/2009 - FFFFFFFF:0
16/06/2010 - FFD9D9D9:0
14/05/2011 - FFD9D9D9:0
07/12/2007 - FFFFFFFF:0
22/02/2009 - FFFFFFFF:0
25/10/2009 - FFFFFFFF:0
11/08/2008 - FFFFFFFF:0
29/10/2009 - FFFFFFFF:0
06/09/2010 - FFFFFFFF:0
24/06/2011开发者_StackOverflow - FFE60000:0 //red
15/08/2008 - FFFFFFFF:0
17/09/2010 - FFFFFFFF:0
27/03/2011 - FFFFFFFF:0
19/05/2008 - FFFFFFFF:0
26/05/2009 - FFFFFFFF:0
03/09/2010 - FFFFFFFF:0
25/04/2011 - null       //white
22/06/2011 - FFFFF2B9:0 //yellow
25/09/2009 - FFFFFFFF:0
20/04/2011 - FFFFFFFF:0
16/06/2011 - FFFFF2B9:0 //yellow
02/03/2010 - FFD9D9D9:0
31/01/2011 - FFD9D9D9:0
03/06/2011 - FFFFF2B9:0 //yellow
03/07/2010 - FFFFFFFF:0
12/09/2010 - FFFFFFFF:0
14/11/2010 - FFE60000:0 //red
23/06/2011 - FFFFF2B9:0 //yellow
24/06/2011 - FFFFF2B9:0 //yellow
18/09/2010 - FFD9D9D9:0
11/03/2011 - FFD9D9D9:0
25/12/2010 - null       //white
17/05/2011 - FFEEECE1:0 //blue
27/03/2010 - FFFFFFFF:0
12/03/2011 - FFFFFFFF:0
14/03/2011 - FFFFFFFF:0


Promoting Comment of OP:

Thanks for pointing me in right direction. I unziped and looked at the styles.xml. Could see some elements with with tint values. When I now get the tint value in poi the grey cells above show as: 06/04/2007 - FFFFFFFF:0:-0.1499984740745262 I can rely on poi now :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜