首页 > 解决方案 > 还有其他人在使用 Apache POI 向 Excel 添加纯色背景颜色时遇到问题吗?

问题描述

创建 Excel 电子表格时,我无法在 Apache POI 中使用纯色背景颜色。这是代码。

    XSSFFont calibri_8 = workbook.createFont();
    calibri_8.setFontHeight(8);
    calibri_8.setColor(IndexedColors.BLACK.getIndex());
    calibri_8.setBold(true);

    XSSFCellStyle normalCenteredBeige_8_Wrapped = workbook.createCellStyle();
    normalCenteredBeige_8_Wrapped.setWrapText(true);
    normalCenteredBeige_8_Wrapped.setVerticalAlignment(
            VerticalAlignment.CENTER);
    normalCenteredBeige_8_Wrapped.setAlignment(HorizontalAlignment.CENTER);
    normalCenteredBeige_8_Wrapped.setFont(calibri_8);
    normalCenteredBeige_8_Wrapped.setFillBackgroundColor(new XSSFColor(
            new Color(255, 235, 155), new DefaultIndexedColorMap()));
    normalCenteredBeige_8_Wrapped.setFillPattern(
            FillPatternType.SOLID_FOREGROUND);

我运行代码,输出看起来像这样。

在此处输入图像描述

应该有浅黄色背景的细胞是纯黑色的。在搜索了可用的文档后,似乎没有其他人遇到此问题。我很确定我正确地遵循了背景颜色的指南。非常感谢任何见解。我正在使用 POI 4.1.1。

标签: apache-poi

解决方案


推荐阅读