我用下面的方法得到了 RGB 颜色
public short getRGBColor(int red, int green, int blue){
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFPalette palette = hwb.getCustomPalette();
return palette.findSimilarColor(red,green, blue).getIndex();
}
然后调用下面的方法
public CellStyle createStyles(Workbook wb){
CellStyle style;
Font font1 = wb.createFont();
font1.setBold(false);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setFillForegroundColor(getRGBColor(211,225,237));
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFont(font1);
return style;
}
最佳答案
根据文档,setFillForegroundColor
的参数可以是枚举 IndexedColors
或 setFillBackgroundColor(XSSFColor color)
中的索引值。
尝试使用 XSSFColor 类中的 setRGB
示例代码 -
headerCellStyle.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
关于java - 为什么 Apache POI 无法使用 RGB 获取我选择的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52530159/