15
Views
3
Comments
[Advanced Excel] How to I remove background color of a cell range
advanced-excel
Service icon
Forge asset by Carlos Freitas
Application Type
Service

I want to remove the background color of a range of cells. For that, I use the action Cell_FormatRange, which has an input parameter CellFormat. This is a structure with a text atttribute BackgroundColor, which should contain a color in hex format. But I do not want to set a color, but remove the color.
I tried to set the background color to white ("0x00FFFFFF") but the first value 00 is not set in the alpha channel, so it is not transparent. The result is that the borders in the Excel are hidden:

How can I remove the fill, meaning, set the background transparent? Please note that leaving the attribute empty will not remove the background color but it leaves the color as is.


2024-01-31 05-29-41
Akshay Deshpande

Hey  Rogier👋

If you just leave the BackgroundColor empty, Excel keeps the last fill — it doesn’t actually remove it. To clear the background completely, try passing either  NullTextIdentifier() or an empty string "" in the BackgroundColor field.

Example

CellFormat.BackgroundColor = NullTextIdentifier()

or

CellFormat.BackgroundColor = ""

This tells Excel to remove the fill instead of setting a new color. Once you do that, the cells will go back to transparent (no background).

Hope that helps 😊

Thanks and Regards,
Akshay Deshpande

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Since BackgroundColor is not an identifier, you should not use NullTextIdentifier(). Also, the OP showed a mapping, and not setting a mapping automatically sets it to the default value, which is an empty string already.

2020-09-04 11-39-50
Rogier Olde Dubbelink

I found this in the source code:


            if (!string.IsNullOrEmpty(format.ssSTCellFormat.ssBackgroundColor))

            {

                Color color = ConvertFromColorCode(format.ssSTCellFormat.ssBackgroundColor);

                range.Style.Fill.PatternType = ExcelFillStyle.Solid;

                range.Style.Fill.BackgroundColor.SetColor(color);

            }

So it seems not supported...

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.