gpt4 book ai didi

java - Apache POI Excel 行颜色只有黑色并且不会改变

转载 作者:行者123 更新时间:2023-12-03 03:29:46 37 4
gpt4 key购买 nike

我正在尝试将 Excel 文件背景设为一行白色和其他水绿色。但由于某种原因,无论我做什么,颜色总是会变成黑色。

private void writeTable(Table table, Row row, CellStyle style){
if(row.getRowNum() % 2 == 0) {
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
}
style.setWrapText(true);
Cell cell = row.createCell(0);
cell.setCellValue(table.index);
cell.setCellStyle(style);

//And it continues with other cells
}

无论我做什么,它都不会改变,即使我尝试 GREY_25_PERCENT 它完全是黑色的。 Here's picture of my excel file

最佳答案

这可能看起来违反直觉,但使用

style.setFillPattern(CellStyle.SOLID_FOREGROUND);

结合

style.setFillForegroundColor(IndexedColors.AQUA.getIndex());

设置单元格的背景颜色。

单元格背景本身可能也由两层组成:前景和背景。

关于java - Apache POI Excel 行颜色只有黑色并且不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46173966/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com