设置前景色HSSFCellStyle总是冒出来的黑 [英] Setting foreground color for HSSFCellStyle is always coming out black
本文介绍了设置前景色HSSFCellStyle总是冒出来的黑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用POI Java创建一个Excel US preadsheet。我有用于创建标题行下面的code:
I am using POI to create an Excel spreadsheet in Java. I have the following code used for creating a header row:
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Report");
// some more code
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(cellNumber);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
HSSFFont font = wb.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);
我遇到的问题是,设置在单元格的填充背景色永远是黑色的,不管我选择什么样的颜色。我究竟做错了什么?如果我不使用setFillPattern行,没有颜色显示出来的。
The issue I am having is that setting the fill background color on the cell always comes out black, no matter what color I pick. What am I doing wrong? If I don't use the "setFillPattern" line, no color shows up at all.
推荐答案
我得到这个工作。我必须设置前景色为使背景色工作(??)。
I got this to work. I had to set the foreground color to make the background color work (??).
所以,我改变:
cellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
到
cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
和它的工作!
这篇关于设置前景色HSSFCellStyle总是冒出来的黑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文