在Apache POI中为XSSFWorkbook设置自定义字体颜色 | 您所在的位置:网站首页 › poi设置字体为白色 › 在Apache POI中为XSSFWorkbook设置自定义字体颜色 |
百度翻译此文
有道翻译此文
问题描述
I'm having a little trouble with setting a custom font color for an XSSFWorkbook from Apache POI. When I do: yellow = workbook.createCellStyle(); Font whiteFont = workbook.createFont(); whiteFont.setColor(new XSSFColor(new Color(255, 255, 255)).getIndexed()); yellow.setFillForegroundColor(new XSSFColor(yellowRGB)); yellow.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); yellow.setFont(whiteFont);The font stays black, I'm not sure what I'm doing wrong though. 推荐答案You can do whiteFont.setColor(new XSSFColor(new Color(255,255,255))); However, there is a bug in Apache POI, where it is switching black and white. It looks like they put a 'fix' in XSSFColor.java (look at XSSFColor.correctRGB()) to correct for a problem in Excel. It's likely that Excel was fixed, but Apache POI wasn't updated. Instead you can do: whiteFont.setColor(HSSFColor.WHITE.index) or whiteFont.setColor(IndexedColors.WHITE.index); (this is deprecated) or if you do whiteFont.setColor(new XSSFColor(new Color(255,255,254))); it'll be really close to white. 其他推荐答案XSSFFont font = (XSSFFont) wb.createFont(); font.setColor(new XSSFColor( Color.decode("#7CFC00"))); |
CopyRight 2018-2019 实验室设备网 版权所有 |