How do we get background color
of a XSSFCell
. I tried using XSSFCellStyle
but no luck.
FileInputStream fis = new FileInputStream(fileName);
XSSFWorkbook book = new XSSFWorkbook(fis);
XSSFSheet sheet = book.getSheetAt(0);
XSSFRow row = sheet.getRow(0);
System.out.println(row.getCell(0).getCellStyle().getFillForegroundColor());
Using these steps I am not able to get background color representation in Short
type.
The following is in Scala but it does show exactly how to get the colour from the object model. I wanted to instantiate a java.awt.Color object from the actual rgb values (which is useful partly because my debugger displays for me the actual colour of the object when I stop at breakpoints, and partly because this is for export to systems that have nothing to do with Excel). I'm ignoring the colour's alpha value and my Scala may be a bit naive. I'd suggest that if this doesn't work for you, you should set a break-point and examine the result of closely related method calls such as getFillBackgroundColorColor()
Try this:
Notice that
Color
is used twiceAll the time its giving me no 64 this is my code
Checkout this URL:
https://issues.apache.org/bugzilla/show_bug.cgi?id=45492
This returns the RGB codes but not exact ones. But its more or less the same color returned when compared with the actual color code in the XLS custom color picker.
I'm working in scala but it's the same. Your code is right.
This is my, see if you can find differences:
in my case the result is 64