gpt4 book ai didi

java - 无法设置填充颜色 Apache POI Excel 工作簿

转载 作者:IT老高 更新时间:2023-10-28 21:11:28 25 4
gpt4 key购买 nike

我一遍又一遍地扫描这个论坛并尝试了这里提到的所有方法,但仍然无法让 Apache POI 更改以填充我的 excel 文档的背景颜色。

这是我的代码:

errorOccured = true;
XSSFCellStyle cs = workbook.createCellStyle();
cs.setFillBackgroundColor(IndexedColors.RED.getIndex());
row.getCell(0).setCellStyle(cs);

你知道为什么这行不通吗?让 row.getCell(0) 用红色(背景色)填充的正确方法是什么?

谢谢!

最佳答案

使用前景色代替背景色。

 errorOccured = true;
XSSFCellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(IndexedColors.RED.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
row.getCell(0).setCellStyle(style);

这将用红色填充单元格背景颜色。

关于java - 无法设置填充颜色 Apache POI Excel 工作簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17243529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com