且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Apache POI中为XSSFWorkbook设置自定义字体颜色

更新时间:2022-02-28 08:31:54

您可以执行 whiteFont.setColor(new XSSFColor(new Color(255,255,255)));

但是,Apache POI中有一个错误,正在切换黑白.看来他们在 XSSFColor.java (请查看XSSFColor.correctRGB()),以解决Excel中的问题.Excel可能已修复,但Apache POI尚未更新.

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.

您可以执行以下操作: whiteFont.setColor(HSSFColor.WHITE.index) whiteFont.setColor(IndexedColors.WHITE.index); (已弃用)

Instead you can do: whiteFont.setColor(HSSFColor.WHITE.index) or whiteFont.setColor(IndexedColors.WHITE.index); (this is deprecated)

或者如果您执行 whiteFont.setColor(new XSSFColor(new Color(255,255,254))); 它将非常接近白色.

or if you do whiteFont.setColor(new XSSFColor(new Color(255,255,254))); it'll be really close to white.