Documents for Word .NET Edition
Features / Themes
In This Topic
    Themes
    In This Topic

    Themes, in a Word document, helps in making the global formatting changes, giving your document a consistent and professional look. Hence, themes are generally used to reinforce a brand across every document that is generated by a business.

    GcWord allows you to customize the themes applied to a Word document through the Theme class which can be accessed using Theme property of the GcWordDocument class. The Theme class saves the font and colors that would be used in the document using the FontScheme and ColorScheme properties.

    The theme font can be set using the FontScheme property of the Theme class. This property is of type FontScheme class which provides the MajorFont and MinorFont properties to specify the font for heading and body respectively.

    And, to set the theme colors you would need to fetch the theme color scheme using the GetThemeColor method of the Settings class which accepts the ThemeColorId as a parameter. This method returns an instance of the ThemeColor class, which provides the RGB property to set the value of a color in the color scheme of the theme.

    To change the theme color and font in a Word document:

    1. Access the color scheme of the document using GetThemeColor method of the Settings class.
    2. Set the value of a color in the color scheme of the theme using the RGB property of the ThemeColor class. For example, set dark
      orange color for Accent1 theme color and dark blue color for the hyperlink theme color.
    3. Access the font scheme for the document using FontScheme property of the Theme class.
    4. Set the theme font for heading and body of the document using the Name property of the ThemeFont class.
      C#
      Copy Code
      GcWordDocument doc = new GcWordDocument();
      var section = doc.Body.Sections.First;
      
      //Add Heading
      section.GetRange().Paragraphs.Add("Working with Themes",
                doc.Styles[BuiltInStyleId.Heading1]);
      
      //Add the first paragraph          
      var p = section.GetRange().Paragraphs.Add(
          "This sample shows how you can access and manipulate" +
          " the document theme properties." +
          " For more information, refer to ");
      
      //Add a hyperlink
      Hyperlink link1 = p.GetRange().Hyperlinks.Add(
       new Uri("http://help.grapecity.com/gcdocs/gcword/onlinehelp/webframe.html"),
               "", "GcWord documentation.");
      
      //Customizing the color scheme(theme colors) of the document.
      //Setting the Accent1 theme color
      doc.Settings.GetThemeColor[ThemeColorId.Accent1].RGB = Color.DarkOrange;
      
      //Setting the Hyperlink theme color
      doc.Settings.GetThemeColor[ThemeColorId.Hyperlink].RGB = Color.DarkBlue;
      
      //Setting the FollowedHyperlink theme color
      doc.Settings.GetThemeColor[ThemeColorId.FollowedHyperlink].RGB = Color.DarkGray;
      
      //Customizing the font scheme(theme fonts) of the document
      //Setting Major(Heading) theme font for Latin characters
      doc.Theme.FontScheme.MajorFont.Latin.Name = "Calibri";
      
      //Setting Minor(Body) theme font for Latin characters
      doc.Theme.FontScheme.MinorFont.Latin.Name = "Century Gothic";
      
      //Saves the document
      doc.Save("Themes.docx");

    For more information on how to modify theme colors using GcWord, see GcWord sample browser.