Apply Theme

Spread.Services Documentation
Apply Theme
Collapse All Expand All

Spread.Services Documentation > Developer's Guide > Customize User Interaction > Manage Workbook > Apply Theme

You can apply either a built-in theme or a custom theme to a workbook. The default theme of a workbook is the standard Office theme. In Spread.Services, 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
- Add a custom theme and set to workbook

### 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, Spread.Services 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 Add method of Themes class to add a custom theme. For this, you first need to create an instance of the Themes class and initialize it. 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
--- | ---

    Themes themes = new Themes();

    //base theme is office theme when not give parameter.
    ITheme theme = themes.Add("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";
    workbook.Theme = theme;

    // Applying theme
    worksheet.Range["E10"].Value = "CustomTest";
    worksheet.Range["E10"].Font.ThemeColor = ThemeColor.Light1;
    worksheet.Range["E10"].Interior.ThemeColor = ThemeColor.Accent1;

Copyright © GrapeCity, inc. All rights reserved.