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.
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
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.
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...