如何将单元格的背景颜色设置为任何RGB值?
问题描述:
我想一个单元格的背景颜色设置为这样如何将单元格的背景颜色设置为任何RGB值?
XSSFCellStyle instructionStyle = wb.createCellStyle();
instructionStyle.setWrapText(true);
XSSFColor myColor = new XSSFColor(new java.awt.Color(0, 73,144));
instructionStyle.setFillForegroundColor(myColor);
instructionStyle.setAlignment(HorizontalAlignment.CENTER);
的RGB值,甚至将其编译的是水平对齐一边向中央有一个小区的look.can有人告诉我,没有其他作用此代码有什么问题?谢谢
答
你可以尝试添加以下内容吗?
instructionStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+0
谢谢,那有效。但为什么? –
+0
Axel Richter在他的评论中回答了这个问题。这只是这个API的工作方式。默认填充模式不会填充... – Phil
请参见[快速指南填充和颜色](https://poi.apache.org/spreadsheet/quick-guide.html#Fills+and+colors)。请注意设置[CellStyle.setFillPattern](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/CellStyle.html#setFillPattern%28org.apache.poi.ss.usermodel.FillPatternType% 29)。所以对于实际的'apache poi'版本:'instructionStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);'。 @ apache-poi:更新你的快速指南! –