We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to set Excel cell color to "no fill"

I'm trying to clear the color from a cell in an existing Excel file, and I can't find a way to do it without setting the cell background to white, which isn't the same as selecting no fill from the Excel fill color menu. I've tried the following:

sheet[rowIndex, colIndex].CellStyle.Interior.Color = Color.Empty;
sheet[rowIndex, colIndex].CellStyle.Interior.ColorIndex = ExcelKnownColors.None;

Both result in the cell appearing black, but, if I select the cell, No fill seems to be selected in the fill menu (see attached). Reselecting No fill clears the color from the cell.

Is there something I'm missing?



cell color sample_b31f6f4a.zip

6 Replies

SR Sridhar Syncfusion Team February 11, 2011 07:29 AM UTC

Hi Amanda,

Thanks you for using Syncfusion products.

This is the default in our excel when giving the Cell color to none it automatically shows as black. This is default behavious of XlsIO.
We suggest you to make the following steps for Nofill options as an workaround.

1. Modify the background color to White so that the balck will change to the default.

2. Or else use the patterns color to Nofill.

3. And make the ExcelColorIndex value to White color.

Please let us know if you have any queries.

Thanks,
Sridhar.s



NK NOLONGERWITHCOMPANYAmanda Kabak February 16, 2011 09:18 PM UTC

Could you give me some code samples for the work around? I tried these:

for 1. Modify the background color to White so that the balck will change to the default:

sheet[rowIndex, colIndex].CellStyle.Interior.Color = Color.White;

for 2. Or else use the patterns color to Nofill (I couldn't find any nofill option):

sheet[rowIndex, colIndex].CellStyle.PatternColorIndex = ExcelKnownColors.None;

for 3. And make the ExcelColorIndex value to White color:

sheet[rowIndex, colIndex].CellStyle.Interior.ColorIndex = ExcelKnownColors.White;

All of these make the cells white (which isn't the same as nofill), but they also destroys the default borders on the cell.

I've always liked the support Syncfusion has given in the past, but to say that the way XLSIO works is wrong by default and then not to supply code for the workarounds is pretty shabby.

Is there a way in code to mimic the nofill option? Coloring cells white isn't it because it destroys default borders.




SR Sridhar Syncfusion Team February 17, 2011 06:34 AM UTC

HI Amanda,

Thanks for the update.

We have created the worksround (c# code snippet) helps you to retain the cell with nofill option, and it also retains the cell border. please try it your side and let us know if this helps you.We highly regret for the inconvenience.

Workaround:

C# Code Snippet:

sheet.Range["A3:AE4"].CellStyle.FillPattern = ExcelPattern.None;

Please let us know if you have any queries.

Thanks,
Sridhar.S



NK NOLONGERWITHCOMPANYAmanda Kabak February 17, 2011 03:11 PM UTC

Yes, this works perfectly. Thanks for the code.



SR Sridhar Syncfusion Team February 18, 2011 05:02 AM UTC

Hi Amanda,

Thanks for the update.

We are very happy to help you,and please get back to us if you need any help.

Please let us know if you have any clarifications.

Thanks,
Sridhar.S



NI nivabeath November 5, 2014 07:30 AM UTC

Check this one.....All about C# Excel Formatting
 
Niva

Loader.
Live Chat Icon For mobile
Up arrow icon