How to set Excel cell color to "no fill"

Thread ID:

Created:

Updated:

Platform:

Replies:

98169 Feb 10,2011 11:28 AM Feb 18,2011 12:02 AM ASP.NET (Classic) 5
loading
Tags: XlsIO
NOLONGERWITHCOMPANYAmanda Kabak
Asked on February 10, 2011 11:28 AM
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
Sridhar [Syncfusion]
Replied on February 11, 2011 02:29 AM
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

NOLONGERWITHCOMPANYAmanda Kabak
Replied on February 16, 2011 04:18 PM
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.


Sridhar [Syncfusion]
Replied on February 17, 2011 01:34 AM
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

NOLONGERWITHCOMPANYAmanda Kabak
Replied on February 17, 2011 10:11 AM
Yes, this works perfectly. Thanks for the code.

Sridhar [Syncfusion]
Replied on February 18, 2011 12:02 AM
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