Bug 46493

Summary: BackGround color not working
Product: POI Reporter: Rama Krishna G <bcaramu>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED WONTFIX    
Severity: major CC: bcaramu, wobblycogs
Priority: P1    
Version: 3.2-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Rama Krishna G 2009-01-08 05:19:12 UTC
HSSFCellStyle.setFillBackgroundColor not working
Comment 1 Yegor Kozlov 2009-01-08 07:10:04 UTC
post sample code to reproduce the problem.
Also, see the Quick Guide:
http://poi.apache.org/spreadsheet/quick-guide.html#FillsAndFrills

Yegor
Comment 2 Graham Smith 2009-01-21 11:15:05 UTC
I don't know about version 3.2 but in 3.5 beta 4 the following code (with suitable code around it to create a workbook and save it etc) doesn't create a cell with a light blue background - the background is white. This functionality worked in 3.5 beta 3 (but setting the font as bold didn't work).

Font font = wb.createFont();
font.setBoldweight( Font.BOLDWEIGHT_BOLD );

CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor( IndexedColors.LIGHT_BLUE.getIndex() );
style.setFont( font );

Cell cell = row.createCell( 0 );
cell.setCellStyle( style );
cell.setCellValue( "foo" );
Comment 3 Yegor Kozlov 2009-01-29 08:19:18 UTC
You need to set the type of fill pattern.  The following snippet of code works fine to me:

        CellStyle style = wb.createCellStyle();
        style.setFillForegroundColor( IndexedColors.LIGHT_BLUE.getIndex() );
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style.setFont( font );

        Cell cell = row.createCell( 0 );
        cell.setCellStyle( style );
        cell.setCellValue( "foo" );

See the quick guide: http://poi.apache.org/spreadsheet/quick-guide.html

Yegor