我用下面的方法用 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;}这是我选择的颜色代码 211,225,237 但是 getRGBColor 方法返回另一个颜色代码 204,204,255
3 回答
慕田峪9158850
TA贡献1794条经验 获得超7个赞
正如您在docs 中所读到的,该方法findSimilarColor
在自定义调色板中找到最接近的匹配颜色。您可以尝试使用 方法获得准确的颜色findColor
。但请注意,该方法findColor
可以返回null
.
添加回答
举报
0/150
提交
取消