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

查看:43
本文介绍了无法设置填充颜色 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 foreground 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天全站免登陆