aF.
aF.

Reputation: 66697

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

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?

Upvotes: 9

Views: 20632

Answers (3)

DeniseMeander
DeniseMeander

Reputation: 838

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.

Upvotes: 1

Geoff
Geoff

Reputation: 8850

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;

Upvotes: 24

John Koerner
John Koerner

Reputation: 38077

Try this:

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

Upvotes: 4

Related Questions