【发布时间】:2019-10-28 16:33:07
【问题描述】:
我尝试了在堆栈溢出上发布的不同解决方案,以将背景颜色应用于 Apache POI 生成的单元格,但没有任何效果。
我正在做类似的事情:
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet(sheetName);
XSSFCellStyle cellStyle = ((XSSFCellStyle) workbook.createCellStyle());
if (styleObject.getBgColor() != null) {
java.awt.Color javaBdgColor = java.awt.Color.decode(voceStyle.getBgColor()); // this is #FFF000
XSSFColor bgColor = new XSSFColor(javaBdgColor, new DefaultIndexedColorMap());
cellStyle.setFillForegroundColor(bgColor.getIndex());
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
}
Row newRow = Rowsheet.createRow(0);
Cell newCell = newRow.createCell(0);
newCell.setCellStyle(cellStyle);
// write file
String pathFileExport = buildPathExportFile("test-export");
FileOutputStream fileOut = new FileOutputStream(pathFileExport);
workbook.write(fileOut);
fileOut.close();
//close workbook
workbook.close();
return Paths.get(pathFileExport);
我认为我的代码中一切正常,但每个像这样样式的单元格都会导致黑色背景。
我对没有字段的调试结果中的“DefaultIndexedColorMap”实例有一些疑问:
此时,我不确定如何解决。 其他帖子中的每个人似乎都能正常工作,但我的背景仍然是深色而不是黄色。
有什么建议吗? 提前致谢!
【问题讨论】:
标签: java spring colors apache-poi apache-poi-4