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

时间:2021-12-09 23:42:11

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.

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

Here is my code:

这是我的代码:

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

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

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

Thank you!

1 个解决方案

#1


55  

Use forground color instead of Background color.

使用forground颜色而不是Background颜色。

 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.

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

#1


55  

Use forground color instead of Background color.

使用forground颜色而不是Background颜色。

 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.

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