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

查看:223
本文介绍了不能设置填充颜色的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.

下面是我的code:

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)?

感谢您!

推荐答案

使用forground颜色,而不是背景颜色。

Use forground color instead of Background color.

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

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

this will fill the cell background color with RED.

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

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