Setting foreground color for HSSFCellStyle is always coming out black

风格不统一 提交于 2019-11-27 19:15:54

I got this to work. I had to set the foreground color to make the background color work (??).

So I changed:

cellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);

to:

cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);

and it worked!

If you are setting the foreground color, use

cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

If you are setting the background color, use

style.setFillPattern(FillPatternType.THICK_BACKWARD_DIAG);

or

style.setFillPattern(FillPatternType.THIN_BACKWARD_DIAG);

The foreground and background colors seem to 'stack' (red + blue = purple) if you set the foreground fill pattern before the background fill pattern, but not the other way round. There are several other fill patterns you can choose from. Note that the color will not be applied if you do not change the default fill pattern.

CellStyle.SOLID_FOREGROUND is deprecated in version 3.15+. Use FillPatternType.SOLID_FOREGROUND instead.

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