Search code examples
c#c#-4.0npoi

Custom color for ICellStyle FillForegroundColor than provided named colors


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?


Solution

  • 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));