I am trying to compare an Excel cell’s color to determine if it matches a known System.Drawing.Color. This code worked in VB6 but when I try to accomplish that in C# I get the error “Operator ‘==’ cannot be applied to operands of type ‘object’ and ‘Color'”. Here is the code:
bool isColored = GetStandardHoursCostCodeCell(page, row).Font.Color == System.Drawing.Color.FromArgb(128, 0, 0);
//Where GetStandardHoursCostCodeCell(page, row) returns a range.
What’s more is when I asked CoPilot about this I got the response to cast the object to System.Drawing.Color, which I did. I got an InvalidCastException. Then I tried casting both sides of the equality expression to System.Drawing.Color and same thing. Any ideas how to get around this would be appreciated! TIA.