Home » excel » How to use no fill for background color of a excel cell using c#?

How to use no fill for background color of a excel cell using c#?

Posted by: admin March 7, 2020 Leave a comment


With this:

using Excel = Microsoft.Office.Interop.Excel; 

I’m opening the excel and after I’m setting the color of the first cell to transparent like this:

xlRange = xlWorkSheet.get_Range("A1");
xlRange.Interior.Color = System.Drawing.Color.Transparent;

The problem is that it puts white and the “borders” disappear. I want to put the “No Fill” option and it’s not working.

I’ve also tried this:

xlRange.Interior.Color = System.Drawing.Color.Empty;

but then it changed the cell color to black.

How can I solve this?

How to&Answers:

Assuming that you want to achieve the same state as a cell’s initial state (in a new worksheet), use this:

xlRange.Interior.ColorIndex = 0;


Try this:

xlRange.Interior.Pattern = Excel.Constants.xlNone;
xlRange.Interior.TintAndShade = 0;
xlRange.Interior.PatternTintAndShade = 0;


Maybe this is just partly related to this question; but I noticed by using

xlRange.Interior.Pattern = Excel.XlPattern.xlPatternNone;;

Also all cell fill color disappears. This is not the case when using:

xlRange.Interior.Pattern = Excel.XlPattern.xlPatternAutomatic;

I was searching for this and came upon this question, so I add this for extra info.