[]
        
(Showing Draft Content)

Themes and Colors

Themes and colors help you enhance the overall appearance of the workbook. The appearance of the workbook contributes significantly to the ability to read, understand, and work with it. DsExcel supports both built-in and custom themes and colors, as described in the following sections:

Themes

DsExcel provides Theme property of Workbook class and IWorkbook interface that allows you to set a theme for the workbook. You can change the current theme of the workbook using Theme property and Themes class. The default theme of a workbook is the standard Office theme.

Furthermore, DsExcel also provides Theme class that enables you to create a custom theme and apply it to set up a workbook according to your preferences and requirements.

When a theme is changed, it affects all areas, including the theme font, theme color, range, chart title, etc. For instance, if you apply a built-in or a custom theme to your workbook, it is likely that the color of the range as well as the font will also be changed in accordance with the modified theme.

Set Built-in Theme

Refer to the following example code to set a built-in theme:

// Change workbook's theme to Berlin.
workbook.Theme = Themes.Berlin;

Set Custom Theme

Refer to the following example code to set a custom theme:

// Add custom theme. Base theme is office theme, if parameters are not given.
Theme theme = new Theme("testtheme");

theme.ThemeColorScheme[ThemeColor.Light1].RGB = Color.AntiqueWhite;
theme.ThemeColorScheme[ThemeColor.Accent1].RGB = Color.AliceBlue;
theme.ThemeFontScheme.Major[FontLanguageIndex.Latin].Name = "Buxton Sketch";
theme.ThemeFontScheme.Minor[FontLanguageIndex.Latin].Name = "Segoe UI";

// Apply theme.
workbook.Theme = theme;

Theme, Standard, and Custom Colors

DsExcel allows you to set the color of a cell, cell border, tab, etc., using theme colors, standard colors, and custom colors. You can set these colors using StringToColor method of ColorUtilities class, ThemeColor property, and ThemeColor enumeration.

ThemeColor property sets the built-in theme colors using ThemeColor enumeration. Whereas StringToColor method of ColorUtilities class sets the standard and custom colors using different color string formats, such as:

  • Color name: A predefined standard color name.

    Example: "red".

  • RGB: rgb(r,g,b)

    Example: "rgb(255,0,0)" for red.

  • RGBA: rgba(r,g,b,a)

    Example: "rgba(255,0,0,0.5)" for red with 50% opacity.

  • Hexadecimal: #RGB or #RRGGBB

    Example: "#F00" or "#FF0000" for red.

  • Hexadecimal with alpha: #RGBA or #RRGGBBAA

    Example: "#F00C" or "#FF0000CC" for red with 90% opacity.

Set Theme Color

Refer to the following example code to set the interior and border color of a cell to theme color:

// Set interior and border color to theme color.
worksheet.Range["D2"].Interior.ThemeColor = ThemeColor.Accent1;
worksheet.Range["D2"].Borders.ThemeColor = ThemeColor.Accent2;

Set Standard Color

Refer to the following example code to set the interior and border color of a range to standard color:

// Set interior and border color to standard color.
worksheet.Range["B4:D6"].Interior.Color = ColorUtilities.StringToColor("yellow");
worksheet.Range["C4:D6"].Borders.Color = ColorUtilities.StringToColor("black");

Set Custom Color

Refer to the following example code to set the interior and border colors of a range to a custom color using RGB and hexadecimal color strings:

// Set interior and border color to custom color.
worksheet.Range["B7:B18"].Interior.Color = ColorUtilities.StringToColor("rgb(211,211,211)");
worksheet.Range["B7:D18"].Borders.Color = ColorUtilities.StringToColor("#000000");