java - Apache-POI:创建电子表格时如何设置单元格的背景颜色?
问题描述
在 Apache POI 4.0 中,我想设置一个 Excel 单元格背景颜色,如下所示:
IndexedColorMap colorMap = workbook.getStylesSource().getIndexedColors();
style.setFillForegroundColor(new XSSFColor(java.awt.Color.BLUE, colorMap).getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Row header = sheet.createRow(0);
header.createCell(0).setCellValue("Title");
header.getCell(0).setCellStyle(style);
..但我得到的只是黑色细胞。我尝试了很多东西,但结果总是一样的。
如何在 Apache POI 4.0 中设置 Excel 单元格的背景颜色?
解决方案
尝试使用以下代码作为背景样式
style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
推荐阅读
- python - Django 模型表单验证未验证
- typescript - 如何修复避免在打字稿中引用未绑定的方法错误?
- c++ - 为什么 `std::lock` 不使用全局排序锁定互斥锁?
- javascript - Pug (Jade) 模板引擎使我的字符串变形
- jquery - 如何使用 jQuery 更改背景颜色
- reactjs - 不能在使用反应的全日历中同时使用 select 和 eventClick
- java - 为什么 MAP 使用通用通配符 extends Object 不能容纳任何类型?
- symfony - Easy Admin 3. 如何根据用户角色控制从数据库返回哪些对象?
- byte-buddy - setAccessible(true) 的 ByteBuddy 等价物是什么?
- swift - 如何从集合视图的单元格内的图像视图访问图像?