Java (Apache POI) Detect cell bakground gold color

2019-08-24 10:40发布

问题:

I've been searching for this but I couldn't find a solution.

I have a workbook and I have to check if a cell has the Excel Gold color as background.

something like:

if(cell.getCellStyle().getFillForegroundColorColor().equals(gold) ){ then do something

I tried with HSSF and RGB colors but I can't get it work.

I really apreciate some help.

THanks!

回答1:

You can use

 if(cell.getCellStyle().getFillForegroundColor()==HSSFColor.GOLD.index){
   //do whatever you want
 }


回答2:

this should work:

if(cell.getCellStyle().getFillForegroundColor().equals(HSSFColor.GOLD) ) 
{   
}