Workbook Themes
- 8 minutes to read
A workbook theme defines colors, fonts, and visual effects. Cell formatting, cell styles, and table styles can refer to theme colors. Shapes can also use theme colors, fonts, and visual effects. Use the Workbook.Theme property to access the workbook theme.
A new workbook uses the Office Theme with Office 2007–2010 colors and fonts. A loaded workbook contains the theme from the source document.
Theme Components
A Theme object contains the following components:
| Property | Description |
|---|---|
| ColorScheme | Contains 12 theme colors: dark and light colors for text and backgrounds, six accent colors, and hyperlink colors. |
| FontScheme | Contains the major (heading) and minor (body text) theme fonts. |
| FormatScheme | Contains fills, background fills, line styles, and effects for shapes. |
Use the Theme.Name property to specify the theme name. ThemeColorScheme.Name, ThemeFontScheme.Name, and ThemeFormatScheme.Name properties specify scheme names. A name change does not modify theme colors, fonts, or effects.
Theme Colors
A theme color identifies a color in the workbook’s theme color scheme. It does not store a specific RGB value. The actual color depends on the corresponding color in the theme.
Call the CellColor.FromTheme(themeColor, tint) method to specify a theme color for a font, fill, or border.
Use one of the following ColorSchemeIndexType values to specify a theme color:
| Value | Description |
|---|---|
| Dark1 | The first dark color. |
| Light1 | The first light color. |
| Dark2 | The second dark color. |
| Light2 | The second light color. |
| Accent1 | The first accent color. |
| Accent2 | The second accent color. |
| Accent3 | The third accent color. |
| Accent4 | The fourth accent color. |
| Accent5 | The fifth accent color. |
| Accent6 | The sixth accent color. |
| Hyperlink | The color for hyperlinks. |
| FollowedHyperlink | The color for followed (visited) hyperlinks. |
The tint parameter lightens (positive values) or darkens (negative values) the theme color. Each theme color has a ThemeColorScheme property with the same name that specifies the color value. For example, the ThemeColorScheme.Accent1 property specifies the Accent1 color.
Predefined cell styles also refer to theme colors. For example, the predefined Accent1 cell style uses the Accent1 theme color for the cell fill, and the Hyperlink style applies the Hyperlink theme color to text.
To get the RGB value of a theme color in a specific workbook, call the Workbook.ResolveColor(color) method. The ResolveColor method applies the tint.
The following code snippet fills cell A1 with the Accent1 theme color, modifies the Accent1 color in the theme, and gets the new RGB value of the cell fill:
CellColor accent = CellColor.FromTheme(ColorSchemeIndexType.Accent1);
worksheet.Cells["A1"].Format.Fill = new SolidFillFormat(accent);
workbook.Theme.ColorScheme.Accent1 = new OfficeColor(Color.FromArgb(0x1F, 0x4E, 0x79));
Color fillColor = workbook.ResolveColor(accent);
Theme Fonts
The font scheme contains the major font (MajorFont) for headings and the minor font (MinorFont) for body text. Each theme font is a ThemeFont object that specifies typefaces for Latin, East Asian, and complex script text.
In a new workbook, the Normal cell style follows the minor theme font, and the Title style follows the major theme font.
To link a cell font to a theme font, call the FontFormat.WithSchemeStyle(value) method and pass the Major or Minor value. To link the font of a table style element to a theme font, call the DifferentialFontFormat.WithSchemeStyle(value) method.
The FontFormat.Name property stores the specified font name. If the font uses a theme scheme style, the workbook renders text with the corresponding font from the current theme. For example, text with the Major scheme style uses the current MajorFont. If you modify the font scheme, the text follows the new theme font.
Note
The FontFormat.WithName(value) method resets the scheme style to None. To specify a font name and a scheme style, call the WithName method before the WithSchemeStyle method.
The following code snippet applies the Arial font to cell A2 and links the cell font to the minor theme font:
Cell cell = worksheet.Cells["A2"];
// Apply a fixed font: Arial, 14 pt, bold.
cell.Format.Font = new FontFormat("Arial", 14).WithBold(true);
// Link the cell font to the minor theme font.
// The cell keeps the 14 pt size and bold text formatting.
// If you modify the theme font scheme, the cell text follows the new minor font.
string minorFontName = workbook.Theme.FontScheme.MinorFont.LatinFont.Name;
cell.Format.Font = cell.GetEffectiveFormat().Font.Value
.WithName(minorFontName)
.WithSchemeStyle(FontSchemeStyle.Minor);
Apply Theme Colors and Fonts to Cells
The following code snippet applies the major theme font and the Accent1 theme color to the header in cell A1, and fills cells A2:D2 with a lighter tint of the Accent1 color:
using System.IO;
using DevExpress.Docs.Office;
using DevExpress.Docs.Spreadsheet;
Directory.CreateDirectory("output");
using Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
string majorFontName = workbook.Theme.FontScheme.MajorFont.LatinFont.Name;
Cell header = worksheet.Cells["A1"];
header.Value = "Sales Report";
header.Format.Font = new FontFormat(majorFontName, 16)
.WithSchemeStyle(FontSchemeStyle.Major)
.WithColor(CellColor.FromTheme(ColorSchemeIndexType.Accent1));
worksheet.Cells["A2"].Value = "Q1";
worksheet.Cells["B2"].Value = "Q2";
worksheet.Cells["C2"].Value = "Q3";
worksheet.Cells["D2"].Value = "Q4";
worksheet["A2:D2"].ApplyFill(
new SolidFillFormat(
CellColor.FromTheme(ColorSchemeIndexType.Accent1, 0.8)));
using FileStream stream = File.Create(Path.Combine("output", "Document.xlsx"));
workbook.Save(stream);
The following screenshot illustrates the result:

Modify the Workbook Theme
Use ThemeColorScheme properties to specify theme colors. Use ThemeFontScheme.MajorFont and ThemeFontScheme.MinorFont properties to specify theme fonts. Use the ThemeFont(latinFontName, eastAsianFontName, complexScriptFontName) constructor to specify East Asian and complex script typefaces.
The following code snippet loads a workbook, modifies the theme name, Accent1 and Accent2 colors, and theme fonts:
using System.Drawing;
using System.IO;
using DevExpress.Docs;
using DevExpress.Docs.Office;
using DevExpress.Docs.Spreadsheet;
Directory.CreateDirectory("output");
using FileStream input = File.OpenRead("Document.xlsx");
using Workbook workbook = new Workbook(input);
Theme theme = workbook.Theme;
theme.Name = "Corporate";
ThemeColorScheme colors = theme.ColorScheme;
colors.Name = "Corporate Colors";
colors.Accent1 = new OfficeColor(Color.FromArgb(0x1F, 0x4E, 0x79));
colors.Accent2 = new OfficeColor(Color.FromArgb(0xC5, 0x5A, 0x11));
ThemeFontScheme fonts = theme.FontScheme;
fonts.Name = "Corporate Fonts";
fonts.MajorFont = new ThemeFont("Georgia");
fonts.MinorFont = new ThemeFont("Segoe UI");
using FileStream stream = File.Create(Path.Combine("output", "Document.xlsx"));
workbook.Save(stream);
The following screenshot illustrates the result:

Note
A theme color must specify a color value (for example, an RGB or system color). The API throws an ArgumentException if you set the ThemeColorScheme property to an OfficeColor object that refers to a scheme color (SchemeColors).
Copy a Theme from Another Workbook
To apply the theme of another workbook (for example, a corporate template), copy the color, font, and format schemes of the source theme. Call the Clone method of each scheme and assign the copies to the target theme.
The following code snippet applies the theme of the Template.xlsx workbook to the Document.xlsx workbook:
using System.IO;
using DevExpress.Docs.Office;
using DevExpress.Docs.Spreadsheet;
Directory.CreateDirectory("output");
using FileStream templateStream = File.OpenRead("Template.xlsx");
using Workbook template = new Workbook(templateStream);
using FileStream input = File.OpenRead("Document.xlsx");
using Workbook workbook = new Workbook(input);
Theme source = template.Theme;
Theme target = workbook.Theme;
target.Name = source.Name;
target.ColorScheme = source.ColorScheme.Clone();
target.FontScheme = source.FontScheme.Clone();
target.FormatScheme = source.FormatScheme.Clone();
using FileStream stream = File.Create(Path.Combine("output", "Document.xlsx"));
workbook.Save(stream);
Theme Format Scheme
The ThemeFormatScheme object contains the following collections:
A shape can get its fill, outline, and effects from the theme instead of explicit settings. Use the StyledShape.Style property to specify the shape style. ShapeStyle.FillThemeIndex, ShapeStyle.OutlineThemeIndex, and ShapeStyle.EffectThemeIndex properties specify which format scheme styles apply to the shape. Cells can refer to theme colors and fonts, but not to format scheme styles.
Important
Each collection must contain at least three items. If you remove an item from a collection that contains three items, Remove and RemoveAt methods throw an InvalidOperationException.
Refer to the following help topic for additional information: Create and Manage Shapes.