Free Support Forum - aspose.com

Suggestion: Add a list of safe-colors

Tried to set the foreground color of a cell to something different than the standard Excel-supported color and got a black cell color (as some other posters stated here) on a 256 color display.

Not a problem, I simply changed to a “known color”.

But it would be convenient to have a class with all safe colors. I quickly assembled a class from a posting here in the forum, maybe it is usable for you, probably with the “Color17”…“Color56” renamed to match Microsofts Color.Xxx named colors:

///


/// Colors that are safe for using in Excel.
///

public class SafeExcelColors
{
public static readonly Color Black = Color.FromArgb( 0, 0, 0 );
public static readonly Color White = Color.FromArgb( 255, 255, 255 );
public static readonly Color Red = Color.FromArgb( 255, 0, 0 );
public static readonly Color Lime = Color.FromArgb( 0, 255, 0 );
public static readonly Color Blue = Color.FromArgb( 0, 0, 255 );
public static readonly Color Yellow = Color.FromArgb( 255, 255, 0 );
public static readonly Color Magenta = Color.FromArgb( 255, 0, 255 );
public static readonly Color Cyan = Color.FromArgb( 0, 255, 255 );
public static readonly Color Maroon = Color.FromArgb( 128, 0, 0 );
public static readonly Color Green = Color.FromArgb( 0, 128, 0 );
public static readonly Color Navy = Color.FromArgb( 0, 0, 128 );
public static readonly Color Olive = Color.FromArgb( 128, 128, 0 );
public static readonly Color Purple = Color.FromArgb( 128, 0, 128 );
public static readonly Color Teal = Color.FromArgb( 0, 128, 128 );
public static readonly Color Silver = Color.FromArgb( 192, 192, 192 );
public static readonly Color Gray = Color.FromArgb( 128, 128, 128 );
public static readonly Color Color17 = Color.FromArgb( 153, 153, 255 );
public static readonly Color Color18 = Color.FromArgb( 153, 51, 102 );
public static readonly Color Color19 = Color.FromArgb( 255, 255, 204 );
public static readonly Color Color20 = Color.FromArgb( 204, 255, 255 );
public static readonly Color Color21 = Color.FromArgb( 102, 0, 102 );
public static readonly Color Color22 = Color.FromArgb( 255, 128, 128 );
public static readonly Color Color23 = Color.FromArgb( 0, 102, 204 );
public static readonly Color Color24 = Color.FromArgb( 204, 204, 255 );
public static readonly Color Color25 = Color.FromArgb( 0, 0, 128 );
public static readonly Color Color26 = Color.FromArgb( 255, 0, 255 );
public static readonly Color Color27 = Color.FromArgb( 255, 255, 0 );
public static readonly Color Color28 = Color.FromArgb( 0, 255, 255 );
public static readonly Color Color29 = Color.FromArgb( 128, 0, 128 );
public static readonly Color Color30 = Color.FromArgb( 128, 0, 0 );
public static readonly Color Color31 = Color.FromArgb( 0, 128, 128 );
public static readonly Color Color32 = Color.FromArgb( 0, 0, 255 );
public static readonly Color Color33 = Color.FromArgb( 0, 204, 255 );
public static readonly Color Color34 = Color.FromArgb( 204, 255, 255 );
public static readonly Color Color35 = Color.FromArgb( 204, 255, 204 );
public static readonly Color Color36 = Color.FromArgb( 255, 255, 153 );
public static readonly Color Color37 = Color.FromArgb( 153, 204, 255 );
public static readonly Color Color38 = Color.FromArgb( 255, 153, 204 );
public static readonly Color Color39 = Color.FromArgb( 204, 153, 255 );
public static readonly Color Color40 = Color.FromArgb( 255, 204, 153 );
public static readonly Color Color41 = Color.FromArgb( 51, 102, 255 );
public static readonly Color Color42 = Color.FromArgb( 51, 204, 204 );
public static readonly Color Color43 = Color.FromArgb( 153, 204, 0 );
public static readonly Color Color44 = Color.FromArgb( 255, 204, 0 );
public static readonly Color Color45 = Color.FromArgb( 255, 153, 0 );
public static readonly Color Color46 = Color.FromArgb( 255, 102, 0 );
public static readonly Color Color47 = Color.FromArgb( 102, 102, 153 );
public static readonly Color Color48 = Color.FromArgb( 150, 150, 150 );
public static readonly Color Color49 = Color.FromArgb( 0, 51, 102 );
public static readonly Color Color50 = Color.FromArgb( 51, 153, 102 );
public static readonly Color Color51 = Color.FromArgb( 0, 51, 0 );
public static readonly Color Color52 = Color.FromArgb( 51, 51, 0 );
public static readonly Color Color53 = Color.FromArgb( 153, 51, 0 );
public static readonly Color Color54 = Color.FromArgb( 153, 51, 102 );
public static readonly Color Color55 = Color.FromArgb( 51, 51, 153 );
public static readonly Color Color56 = Color.FromArgb( 51, 51, 51 );
}

Hi Uwe,

Thanks for your suggestion.

But please be sure that these 56 colors are safe only in standard color palette. If the color palette is changed in your spreadsheet or changed at run time by Excel.ChangePalette method. It’s not safe.

We provide Excel.Colors property to return all 56 colors in the palette. And Excel.IsColorInPalette method to check if a color is safe.