Document Solutions for Excel, .NET Edition | Document Solutions
Features / Themes and Colors
In This Topic
    Themes and Colors
    In This Topic

    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:

    C#
    Copy Code
    // Change workbook's theme to Berlin.
    workbook.Theme = Themes.Berlin;

    Set Custom Theme

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

    C#
    Copy Code
    // 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:

    Set Theme Color

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

    C#
    Copy Code
    // 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:

    C#
    Copy Code
    // 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:

    C#
    Copy Code
    // 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");