Differentiate white and noFill (transparent) cell color

Hello,

Scenario:
I have two cells in Excel one of which has an explicit white background color, whereas the second one has “NoFill” selected (Excel displays both as white cells).

Question:
I would like to know whether there is a way to differentiate the fillColor of those two cells. I.e. determine that one cell actually has a transparent/noFill background while the other is white.

The use case is as follows:
In my application, I would like to regard the standard noFill option as transparent color and an explicitly set white fillColor as white.

I tried to access the cell.Style.ForegroundColor and the BackgroundColor but both return white with A=255 for both the NoFill and the explicit-white-case.
The cell.Style.ForegroundArgbColor and the BackgroundArgbColor both return “-1” for both cases.
The cell.Style.Pattern is “Solid” in both cases.

Any ideas on that one?

Thanks for your help
Kind regards
Thomas

@tstaufen,

To evaluate nofill or filled colors for the cells, see the following sample code for your reference:
e.g.
Sample code:

        Workbook workbook = new Workbook("e:\\test2\\Book1.xlsx");
        Worksheet worksheet = workbook.Worksheets[0];
        Cell cellA1 = worksheet.Cells["A1"];//it has white color
        Cell cellB1 = worksheet.Cells["A2"];//it has no fill (transparent) or default color.
        
        var style = cellA1.GetStyle();
        //var style = cellB1.GetStyle();

        var foregroundColor = style.ForegroundColor;
        var backgroundPatternColor = style.BackgroundColor;
        var backgroundPattern = style.Pattern;

        Color fillColor = foregroundColor;

        // If the Background Pattern is not None / Solid - use that color for the Font Check 
        switch (backgroundPattern)
        {
            case BackgroundType.None:
                fillColor = Color.Empty;
                break;
            case BackgroundType.Solid:
                fillColor = foregroundColor;
                break;
            default:
                fillColor = backgroundPatternColor;
                break;
        }


        if (fillColor.IsEmpty)
        {
            Console.WriteLine("Transparent or No fill");
        }
        else {

            Console.WriteLine(fillColor.Name);
            Console.WriteLine(fillColor.ToString());
            
        }

Hope, this helps a bit.

Thank you for the quick response.
This resolved my issue.

Thank you for your help
Kind regards
Thomas

@tstaufen,

Good to know that the suggested code segment fixes your issue now. Feel free to write us back if you have further queries or issue.