开发者

How to get excel cell color in java

开发者 https://www.devze.com 2023-04-06 03:00 出处:网络
I have an XSLX sheet in which few cells are having background color 开发者_开发知识库Green, few Red and rest are default(white).

I have an XSLX sheet in which few cells are having background color 开发者_开发知识库Green, few Red and rest are default(white).

How to identify the cell color ? based on the cell color, i have to process the text in the cell. I am using apache poi.

Cell cell = row.getCell(6);
CellStyle style = cell.getCellStyle();
Color cellColor = (cell.getCellStyle().getFillBackgroundColorColor());

if the cellColor will hold the background color of the cell, how can the color name be retrevied from it.

Please Help

thanks Ramm


Don't base it on text value. You're almost there.

Color cellColor = (cell.getCellStyle().getFillBackgroundColorColor());

Now just do:

if(cellColor.equals(Color.GREEN)) {
  //do whatever
}
0

精彩评论

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

关注公众号