Setting background custom color not working for XSSF in Apache POI

那年仲夏 提交于 2019-12-04 22:54:54

You are trying to use an indexed color, but with your code for HSSF the indexed color is found, but not for the XSSF part. There Color.getIndex() will return zero, which is black.

There is a method isIndexed() on color which you need to check if the color is an indexed one and only then it makes sense to use getIndex() on the POI-Color-object.

You can make it work for XSSF by not using indexed colors, but the full color value by using the following:

((XSSFCellStyle)cellStyle).setFillForegroundColor(color);

This way you set the actual color and the resulting workbook will have the correct background.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!