Arushi gupta
Arushi gupta

Reputation: 179

How to get the background colour name of an excel cell(xlsx) using apache POI

Requirement: I want to read an excel sheet and perform some action on the cells that are highlighted in the sheet i.e the cells which have their background colour as yellow.

I went through all the other similar posts but could not get the required information.

I tried using getFillBackgroundColor() which returns me value 64 each time for every colour. I tried using getFillBackgroundColorColor() which returns a colour object but I could not find a way to resolve it to the color name.

Please If anyone can help me with this

Upvotes: 0

Views: 1378

Answers (2)

jmarkmurphy
jmarkmurphy

Reputation: 11493

Fills feel a bit unnatural to me, but it is just the nature of the beast. The fill itself is the cell background, but the fill itself has a foreground and background. So our typical two layer view of the world (foreground/background) doesn't work. In Excel we have three layers: Text color, Fill Foreground color, and Fill Background color. The Solid Fill happens to use the Fill Foreground color rather than the Fill Background color. Only two color fills have a Fill Background Color.

So if you have a solid "background", that means you have a solid fill which means you need to use getFillForegroundColor().

Upvotes: 0

centic
centic

Reputation: 15880

Take a look at the samples at http://poi.apache.org/spreadsheet/quick-guide.html#FillsAndFrills, you might need to use getFillForegroundColor()

Upvotes: 2

Related Questions