C# Colors and Formulas not working with

I have some code that I’m using to try to use ImportCustomObjects. But for some reason no matter what I do I cannot set the colors of the header row. I’m able to manipulate the formatting but the colors are not being set. And the formulas are not executing at the end.

        sheet.Cells.ImportCustomObjects(list: collections, propertyNames: header.ToArray(), isPropertyNameShown: true,
            firstRow: 0, firstColumn: 0, rowNumber: collections.Count, insertRows: true, dateFormatString: dateFormat,
            convertStringToNumber: false);

        for (int i = 0; i < headers.Count; i++)
        {
            var flag = new StyleFlag();
            flag.CellShading = true;
            var style = sheet.Cells[0, i].GetStyle();
            style.BackgroundColor = Color.Orange;
            sheet.Cells[0, i].SetStyle(style, flag);
        }

        wb.Worksheets[0].AutoFitColumns();
        wb.CalculateFormula(new CalculationOptions { Recursive = true });
        wb.Save(fileName: filename, saveFormat: SaveFormat.Xlsx);

@tkurian
Please try the following codes:
var flag = new StyleFlag();
flag.CellShading = true;
var style = sheet.Cells[0, i].GetStyle();
style.Pattern = BackgroundType.Solid;
style.ForegroundColor = Color.Orange;
sheet.Cells[0, i].SetStyle(style, flag);
And please try the docs :Fill Settings|Documentation

Tried it but no luck.

@tkurian
Could you share a sample project with template file ? We will check it soon.

Actually I had a typo it’s working I was using BackgroundColor insteand of Foreground Color & Pattern = Solid.

Thanks for your help.

@tkurian,

It is nice to know that you got it right now. Feel free to write us back if you have further queries or issue, we will be happy to assist you soon.