This project is read-only.

can't set cell background color

Aug 13, 2010 at 10:59 AM
Edited Aug 13, 2010 at 11:05 AM

This is my code


var cell = ws2.CreateRow(i + 1).CreateCell(41);
 var style1 = templateWorkbook.CreateCellStyle();
style1.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.PINK.index;
cell.CellStyle = style1;

However when I open the saved file there is no format change ( the cell value is saved thought)
Aug 13, 2010 at 2:21 PM


You need to set the FillForegroundColor (to fill the "background" of a cell)...


style1.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.PINK.index;

You then need to set the fill pattern...

style1.FillPattern = FillPatternType.SOLID_FOREGROUND;

Hope that helps.