Working with Colors

The Color enum defines Excel colors the can be used throughout the rust_xlsxwriter library.

There are 3 types of colors within the enum:

  1. Predefined named RGB colors like Color::Green.
  2. User defined RGB colors like Color::RGB(0x4F026A).
  3. Theme colors like Color::Theme(9, 4).

These are explained in more detail in the sections below.

Named colors

For convenience there are a number of predefined named colors which are translated internally to RGB colors. These are shown in the table below.

NameValue
Color::Black0x000000
Color::Blue0x0000FF
Color::Brown0x800000
Color::Cyan0x00FFFF
Color::Gray0x808080
Color::Green0x008000
Color::Lime0x00FF00
Color::Magenta0xFF00FF
Color::Navy0x000080
Color::Orange0xFF6600
Color::Pink0xFF00FF
Color::Purple0x800080
Color::Red0xFF0000
Color::Silver0xC0C0C0
Color::White0xFFFFFF
Color::Yellow0xFFFF00
Color::Default None
Color::AutomaticNone

The Color::Default value translates to the default color in whatever context it is used. The Color::Automatic value is usually the same but can be overridden by system settings.

RGB colors

These are the most common colors used throughout Excel. In rust_xlsxwriter they can be generated using the Color::RGB() member of the enum like this: Color::RGB(0x4F026A).

These are similar to HTML style colors which most people will be familiar with.

Theme colors

Theme colors are colors from the standard palette of 60 colors which is shown in the image below.

Image of the Excel theme color palette

The syntax for theme colors in Color is Theme(color, shade) where color is one of the 0-9 values on the top row and shade is the variant in the associated column from 0-5. For example "White, background 1" in the top left is Theme(0, 0) and "Orange, Accent 6, Darker 50%" in the bottom right is Theme(9, 5).

Note, there are no plans to support anything other than the default Excel "Office" theme.