这里仅总结 poi 4.0.0设置单元格背景颜色
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.0.0</version> </dependency>
一、 IndexedColors设置
XSSFCellStyle style = wb.createCellStyle(); style.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); cell.setCellStyle(style);
二、RGB设置
IndexedColorMap colorMap = wb.getStylesSource().getIndexedColors(); XSSFColor color = new XSSFColor(new java.awt.Color(60, 63, 65), colorMap); style.setFillForegroundColor(color); style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
三、 颜色代码设置
XSSFCellStyle style = wb.createCellStyle(); XSSFColor color = new XSSFColor(Hex.decodeHex("FFF000"), null); style.setFillForegroundColor(color); style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
原文:https://www.cnblogs.com/shiqiboy3974/p/14058589.html