我想为我的单元格背景颜色使用自定义 RGB 颜色 (38,38,38)。
为此,我使用以下代码:
IndexedColorMap colorMap = wb.getStylesSource().getIndexedColors();
XSSFColor customtablegrey = new XSSFColor(new java.awt.Color(38,38,38), colorMap);
cellFormat1.setFillForegroundColor(customtablegrey.getIndex());
cellFormat1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
But all I get is a black background. Why and how can I change it?
此致,
基督教
这是真的。IndexedColorMap
是无用的XSSFColor
s. XSSFColor
s 不是索引颜色。在Office Open XML
自定义颜色直接以 RGB 形式存储在 XML 中。它们不存储在任何类型的颜色图中。
Setting XSSFColor
s 作为填充前景色到单元格样式可以使用XSSFCellStyle.setFillForegroundColor(XSSFColor 颜色)仅有的。不能使用它来设置CellStyle.setFillForegroundColor(short fg)
.
So cellFormat1.setFillForegroundColor(customtablegrey)
应该工作时cellFormat1
is a XSSFCellStyle
.
如何使用 Apache POI XSSF Excel 的 IndexedColors 中没有的颜色?显示了如何使用的完整示例XSSFColor
作为单元格填充颜色。刚刚测试使用apache poi 5.1.0
too.
APACHE POI 4.1:从十六进制代码设置单元格背景颜色显示另一个完整的例子。还经过测试并使用apache poi 5.1.0
too.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)