0

我一直在添加背景,如下所示。在 excel 中可以看到所有其他更改,但单元格没有填充颜色。请帮忙

public static CellStyle getWeeklyHeaderStyle(HSSFWorkbook wb) {

    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setWrapText(true);
    cellStyle.setAlignment((short) 1);
    cellStyle.setVerticalAlignment((short) 1);
    cellStyle.setBorderLeft((short) 1);
    cellStyle.setBorderRight((short) 1);
    cellStyle.setBorderTop((short) 1);
    cellStyle.setBorderBottom((short) 1);
    getPalette(wb);
    cellStyle.setFillBackgroundColor(IndexedColors.RED.getIndex());
    cellStyle.setFont(getFont(wb));
    return cellStyle;
}

public static HSSFPalette getPalette(HSSFWorkbook wb) {

    HSSFPalette palette = wb.getCustomPalette();
    // replacing the standard red with freebsd.org red
    palette.setColorAtIndex(IndexedColors.RED.index, (byte) 204, (byte) 204,
            (byte) 255);
    return palette;
}
4

0 回答 0