无法设置填充颜色Apache POI Excel工作簿 [英] Can't Set Fill Color Apache POI Excel Workbook

查看:3116
本文介绍了无法设置填充颜色Apache POI Excel工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经反复扫描这个论坛,并尝试了这里提到的每一种方法,仍然无法获得Apache POI更改以填充我的Excel文档的背景颜色。

I have scanned this forum over and over and tried every method mentioned on here and still can't get Apache POI to change to fill background color of my excel document.

这是我的代码:

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

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

Do you know why this wouldn't work? What is the correct way to get row.getCell(0) to be filled with red (background color)?

谢谢!

推荐答案

使用背景颜色代替背景颜色。

Use forground color instead of Background color.

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

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

this will fill the cell background color with RED.

这篇关于无法设置填充颜色Apache POI Excel工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆