Document Solutions for Excel, .NET Edition | Document Solutions
Features / Theme
In This Topic
    Theme
    In This Topic

    DsExcel .NET provides users with a set of built-in themes to enable them to change the overall appearance of the workbook. Besides, it also allows users to create custom theme and apply it in order to set up a workbook as per their own 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 to the modified theme.

    The default theme of a workbook is the standard Office theme. In DsExcel, the current theme of a workbook is represented by the ITheme interface.

    To change the current theme of the workbook, you need to first get the existing theme using the indexer notation of the Themes class.

    Applying theme in a workbook involves the following tasks:

    Apply built-in theme to the workbook

    In order to enable you to maintain consistency in the appearance across all the worksheets in the workbook, DsExcel offers a set of built-in themes for you to choose from.

    Refer to the following example code to apply a built-in theme to the workbook.

    C#
    Copy Code
    //Change workbook's theme to Berlin.
    worksheet.Range["E10"].Value = "Test";
    worksheet.Range["E10"].Font.ThemeColor = ThemeColor.Accent6;
    worksheet.Range["E10"].Interior.ThemeColor = ThemeColor.Accent5;
    workbook.Theme = Themes.Berlin;

    Add a custom theme and set to workbook

    You can use the Theme object constructor in order to add a custom theme. After you add your custom theme, you can apply it to your workbook.

    Refer to the following example code to add a custom theme and apply it to the workbook.

    C#
    Copy Code
                
    //Add custom theme
    
    Theme theme = new Theme("testtheme");   // Base theme is office theme, if parameters are not given 
    
    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";
    workbook.Theme = theme;
    
    // Applying theme
    worksheet.Range["E10"].Value = "CustomTest";
    worksheet.Range["E10"].Font.ThemeColor = ThemeColor.Light1;
    worksheet.Range["E10"].Interior.ThemeColor = ThemeColor.Accent1;