我使用此代码将 excel 中的字体更改为我定义的颜色
Color sColor = new Color (value,0,0);
XSSFColor userColor = new XSSFColor(sColor);
CellStyle style = wb.createCellStyle();
XSSFFont font = wb.createFont();
font.setColor(userColor);
style.setFont(font);
cell.setCellStyle(style);
我可以以相同的方式更改单元格的背景吗?
我在这里看到了设置背景自定义颜色不适用于 Apache POI 中的 XSSF 的问题,我使用了以下代码:
XSSFCellStyle cellStyle = wb.createCellStyle();
XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));
((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);
cell.setCellStyle(cellStyle);
背景仍然总是白色。
确保代码的所有其他部分都正确编写,因为当我更改字体时它可以工作。
我的电脑上有 office 2010
谢谢我现在找到的解决方案
XSSFCellStyle cellStyle = wb.createCellStyle();
XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));
((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle.setFillForegroundColor(color);
cell.setCellStyle(cellStyle);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句