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?
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));
Sorry, and again.
Color SuperColor = Color.FromArgb(192, 0, 0);
styleH.FillForegroundColor = GetXLColour(hssfworkbook, SuperColor);
private short GetXLColour(HSSFWorkbook workbook, System.Drawing.Color SystemColour)
{
    short s = 0;
    HSSFPalette XlPalette = workbook.GetCustomPalette();
    NPOI.HSSF.Util.HSSFColor XlColour = XlPalette.FindColor(SystemColour.R, SystemColour.G, SystemColour.B);
    if (XlColour == null)
    {
        if (NPOI.HSSF.Record.PaletteRecord.STANDARD_PALETTE_SIZE < 255)
        {
            if (NPOI.HSSF.Record.PaletteRecord.STANDARD_PALETTE_SIZE < 64)
            {
                NPOI.HSSF.Record.PaletteRecord.STANDARD_PALETTE_SIZE = 64;
                NPOI.HSSF.Record.PaletteRecord.STANDARD_PALETTE_SIZE += 1;
                XlColour = XlPalette.AddColor(SystemColour.R, SystemColour.G, SystemColour.B);
            }
            else
            {
                XlColour = XlPalette.FindSimilarColor(SystemColour.R, SystemColour.G, SystemColour.B);
            }
            s = XlColour.GetIndex();
        }
    }
    else
        s = XlColour.GetIndex();
    return s;
}  
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With