如何使用apache pio 4.1.0设置单元格的背景颜色

问题描述 投票:0回答:1

我正在尝试使用setFillBackgroundColor方法设置背景色,但似乎有必要将setFillPattern与它一起使用。但是使用setFillPattern方法无法找到普通的FillPatternType。

cellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
cellStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);

我无法找到普通的fillPatternType,如果我使用NO_FILL,则背景颜色将不适用。如果不使用setFillPattern,则无法看到setFillBackgroundColor的效果。

请让我知道如何设置纯净的背景色,而没有任何点,砖,钻石或DIAG。

感谢。

java apache-poi
1个回答
1
投票

单元内部使用图案填充。填充背景色是图案的颜色[behind]。填充前景色是图案的颜色。 要使用纯色填充单元格,您需要使用填充前景色和纯色图案。

请参见Fills and colors

... cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); ...

© www.soinside.com 2019 - 2024. All rights reserved.