0

I have been adding background as shown below. All other changes are seen in the excel but cell does not get filled with the color. please help

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;
}
Johnny000
  • 2,058
  • 5
  • 30
  • 59
  • Use `setFillForegroundColor` instead of `setFillBackgroundColor` check http://stackoverflow.com/a/17709121/624003 – Sankumarsingh Sep 20 '13 at 07:31
  • i have even tried that. but its working i am stuck up in a bad way. – karan sharma Sep 20 '13 at 07:35
  • i have even tried that. but its nt working. please help me as i am stuck badly. – karan sharma Sep 20 '13 at 07:36
  • You have written a method which is returning `cellstyle`... but you have not used `cell.setCellStyle(cellStyle);` that is used to deploy the cellstyle to the selected cell. – Sankumarsingh Sep 20 '13 at 07:40
  • yeah i have that method in a different class. all other that have been mentioned above are getting applied. even the font which i have it myself. but the color is not getting filled. – karan sharma Sep 20 '13 at 07:49
  • thnx for ur help. but i have done it by adding cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);thnx anyways – karan sharma Sep 20 '13 at 07:53

0 Answers0