Free Support Forum -

Cells Foreground Color seems to be incorrect

I have a Cell in an Excel File where I’m getting styles that doesn’t match what I’m seeing in Excel visually. I have code see if the Font Color is the same as the Fill Color - in case the value would be “invisible”. This Cell (B2), has a Foreground Color of ARGB (255, 0, 0, 0), Font Color of ARGB (255, 0, 0, 0), Background Color of ARGB (255, 255, 255, 255) and a Pattern of None.

If I look at the Cell in Excel - fill color looks like White and font color looks like Black - so it’s not invisible. But, per API Reference, we are supposed to just look at Foreground Color in Aspose for the Fill color. Which appears to be the same as the Font Color. Since the Pattern is None - the Background (Pattern) color, shouldn’t come into play, right?

How can I programmatically check to see if the Font Color and the Fill Color of a cell is the same or not?

We are using Aspose.Cells .NET - version 18.6.0.

Thank you so much for your help!

Attached is the file showing this issue and a screenshot of the property values I’m seeing. (7.3 KB)
Excel-Cell-Style-Mismatch.png (473.5 KB)


Thanks for your query.
I have checked the template file in Excel 2016 and observed that Fill Color is RGB(0,0,0) where as it is white when we see it visually. Same value is displayed by Aspose.Cells. You may please check the scenario with Excel 2016 again and share the feedback. If we change the fill color and font color to some different values than default, Aspose.Cells shows proper foreground color and font color. So it does not seem to be an issue with the API as it is showing same values as Excel 2016.

Thanks for the reply! Sorry, I probably wasn’t clear. My question wasn’t regarding the Font Color - I agree that is Black - RGB (0,0,0).

My question is with regard to the Foreground Color. If I look in Excel - it looks white. But, in Aspose, it shows Black - RGB (0,0,0). Do you know how that could be?

Thank you so much for your help!


We are sorry for the inconvenience.
Open the template file in Excel 2016 and perform the following steps:

  1. Right click on Cell

  2. Select Format Cells…

  3. In the format cells form, click on Fill tab page

  4. Click on combo box “Pattern Color” and click “More Colors…”

  5. On the Colors dialog, select the Custom Dialog

Here you will see that RGB color is 0,0,0 which is Black. Hence Excel shows fill color as RGB(0,0,0) whereas visually the fill color is white. I am afraid that I cannot see RGB(255,255,255) white for the fill color in Excel. Same value RGB(0,0,0) is returned by Aspose.Cells as foreground color thus it does not seem to be an issue.

Please feel free to write us back if you have any other observation in this regard.

Thank you for your response again. I’m sorry, I still think there may be some miscommunication. I have attached C# code so the inconsistency can be be seen - as well as picture of what I’m seeing in Excel.

A couple follow up statements/questions - please let me know if I’m wrong:

  1. Background Color (in Excel) corresponds to "cell.GetDisplayStyle().ForegroundColor"
  2. Pattern Color (in Excel) corresponds to "cell.GetDisplayStyle().BackgroundColor"
  3. I shouldn’t have to worry about Pattern Color in this case. Since the Pattern (“cell.GetDisplayStyle().Pattern”) is None.
  4. For “Fill” Color (to know what the color of the cell is visually in Excel) - I should just be looking at “cell.GetDisplayStyle().ForegroundColor”.
  5. Why does “cell.GetDisplayStyle().ForegroundColor” correspond to ARGB (255, 0, 0, 0), if Background Color in Excel corresponds to RGB (255, 255, 255)?
  6. Why does “cell.GetDisplayStyle().BackgroundColor” correspond to ARGB (255, 255, 255, 255), if Pattern Color in Excel corresponds to RGB (0, 0, 0)?

I’ve created other test files and those process as expected

  • “cell.GetDisplayStyle().ForegroundColor” = Background Color in Excel
  • “cell.GetDisplayStyle().BackgroundColor” = Pattern Color in Excel

For some reason, this file doesn’t conform to that and I don’t understand why.

Thank you for all your time and help with this. (1.4 KB)
CellB2-FillColor.png (146.9 KB)


Regarding your first two queries following are the comments:

  1. Foreground color —> it refers to the background color if the pattern type is null or solid

  2. Background color --> it refers to cell’s filling/background color if the pattern type is neither solid nor null

We were able to observe anomalies in foreground and background color but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46374 - Wrong detection of cell foreground and background color

Thanks Ahsan, I appreciate it! I’m really interested in the final result of the issue.


You are welcome.


Please try our latest version/fix: Aspose.Cells for .NET v18.9.5

Your issue should be fixed in it.

Let us know your feedback.

PS. Please change codes e.g. var row3 = allCells.Rows[2]; as var row3 = allCells.Rows[3];
We only find an issue about “E4”: Color.Black is returned when the background color is automatic and the pattern is not solid and none.

The issues you have found earlier (filed as CELLSNET-46374) have been fixed in Aspose.Cells for .NET v18.10. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi

Hi Support. Thank you for looking into this. I have installed and tried using v18.10 of Aspose.Cells for .NET and am NOT seeing any different results.

When I look at Cells B2, C2, F2, H2 in Aspose, the cell.GetDisplayStyle().ForegroundColor exactly matches cell.GetDisplayStyle().Font.Color. Which, they shouldn’t from what you see visually when you look at the file in Excel.

Any other recommendations?



Thanks for providing us details.

I noticed the issue is there or we need to provide more details with updated example code to make you understand regarding background, foreground and font colors. I have reopened your issue (logged earlier as “CELLSNET-46374”). We will look into it thoroughly and figure it out soon.

Once we have an update on it, we will let you know here.


We have evaluated your issue in details and found your sample code needs some tweaking. Please see the updated code segment which works as I tested with your template file:
Sample code:

var loadOptions = new LoadOptions { ParsingFormulaOnOpen = false };

            var workbook = new Workbook("e:\\test2\\CellColors.xlsx", loadOptions);
            var worksheet = workbook.Worksheets[0];
            var allCells = worksheet.Cells;
            var row2 = allCells.Rows[1];
            var cellB2 = row2[1];

            // Use GetDisplayStyle to make sure we get styles based on Conditional Formatting
            var style = cellB2.GetDisplayStyle();

            var foregroundColor = style.ForegroundColor;
            var fontColor = style.Font.Color;

            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.White;
                case BackgroundType.Solid:
                    fillColor = foregroundColor;
                    fillColor = backgroundPatternColor;

            if (fillColor.IsEmpty)
                // if not set - change to backgroundColor to White to help with the hidden/invisible text issue 
                fillColor = Color.White;

            if (fontColor.IsEmpty)
                // if not set - change to fontColor to Black to help with the hidden/invisible text issue 
                fontColor = Color.Black;

            bool isHiddenText = false;
            // Find out if there is any "hidden" text by having the Font Color match the Background Color 
            if (fillColor.ToArgb() == fontColor.ToArgb())
                isHiddenText = true;

Let us know if you still have any issue.

That definitely works. But, what that means is that GetDisplayStyle().ForegroundColor is incorrect when GetDisplayStyle().Pattern is BackgroundType.None? In a lot of occasions, it has been correct, but this file has been causing issues.

Thanks for your time on this!


Thanks for your feedback. It is good to know your issue is resolved now. If Style.Pattern is BackgroundType.None, Style.ForegroundColor returns Color.Empty in Aspose.Cells.

Let us know if you encounter any issue, we will be glad to look into it and help you further.