Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

excel

c#-4.0

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?

like image 566
aF. Avatar asked Apr 27 '12 14:04

aF.


People also ask

How do I make Excel not fill color?

On the Home tab, in the Font group, click the arrow next to Fill Color, and then click No Fill.

How do you make a cell be a no fill?

The no fill shortcut is a simple keyboard shortcut that allows you to quickly fill a cell with data without using the fill handle. To use the no fill shortcut, simply select the cell you want to fill and press the Ctrl+Shift+F keys on your keyboard. That's it!

How do I make the background of a cell in Excel transparent?

Right-click and then select "Format Cells" from the popup menu. When the Format Cells window appears, select the Fill tab. Next choose the color that you wish to use as the background color or you can choose "No color" to return the cell back to its default transparency.


1 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;
like image 67
Geoff Avatar answered Sep 17 '22 04:09

Geoff