KevinH
KevinH

Reputation: 25

c# epplus not filling background color of cell

Ok I am stumped the set font works and sets the correct cell. The Fill.BackgroundColor.SetColor does not work. It literally does nothing. Am I missing something? Every search I do that syntax should work. Yes this is reading a data table dt that is not the issue the loop works properly.

int startupRow = 2; // row 1 is header

for (int row = startupRow; row <= dt.Rows.Count; row++)
{
    //if allocation check is populated it will have a value > 0
    if (Convert.ToInt32(workSheet.Cells[row, 8].Value) > 0)
    {
        //if Balance Remaining Barrels <  allocation check
        if (Convert.ToInt32(workSheet.Cells[row, 7].Value) < Convert.ToInt32(workSheet.Cells[row, 8].Value))
        {
            //set the font to red 
            var cell = workSheet.Cells[row, 7];
            cell.Style.Font.Color.SetColor(System.Drawing.Color.Red);
            cell.Style.Font.Bold = true;

            //Setting the background color to red
            cell.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
            cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red);

        }
    }
}  
       

Upvotes: 0

Views: 874

Answers (1)

KevinH
KevinH

Reputation: 25

I resolved my own question so hopefully this helps someone else. The border has to be last in the formatting. Certain elements take precedent over other elements and they will disappear.

Upvotes: 0

Related Questions