Bug 46493 - BackGround color not working
Summary: BackGround color not working
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.2-FINAL
Hardware: PC Windows XP
: P1 major (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2009-01-08 05:19 UTC by Rama Krishna G
Modified: 2009-01-29 08:19 UTC (History)
2 users (show)


Note You need to log in before you can comment on or make changes to this bug.
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:

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.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