Custom color for ICellStyle FillForegroundColor than provided named colors

SivaRajini picture SivaRajini · Mar 27, 2014 · Viewed 17.5k times · Source

We are newly started using NPOI components.

We are having issues to set FillForegroundColor of ICellStyle property.

ICellStyle HeaderCellStyle = xssfworkbook.CreateCellStyle(); 

HeaderCellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.RED.index;

FillForegroundColor expects of type short.

How do we set a different color rather than using colors in HSSFColor.

We need to set to "RGB192:0:0" and how do we do that for ICellStyle property FillForegroundColor

Colud someone help us by some example?

Answer

SivaRajini picture SivaRajini · Mar 27, 2014

I found the solution my self. Please refer below code

byte[] rgb = new byte[3] { 192, 0, 0 };
 XSSFCellStyle HeaderCellStyle1 = (XSSFCellStyle)xssfworkbook.CreateCellStyle();
 HeaderCellStyle1.SetFillForegroundColor(new XSSFColor(rgb));