Skip to main content
A newer version of this page is available. .

Styles

  • 2 minutes to read

A document model contains collections of styles. There are three types of styles - a paragraph style, a character style and a table style. Styles are accessible via the Document.ParagraphStyles, Document.CharacterStyles and Document.TableStyles properties, respectively.

Use the CharacterStyleCollection.CreateNew, ParagraphStyleCollection.CreateNew and TableStyleCollection.CreateNew methods to create new styles. After creating a new style, specify style formatting and add it to the corresponding style collection using the collection’s Add method. You do not have to specify all formatting properties. Instead, you can specify the parent style (the CharacterStyle.Parent, ParagraphStyle.Parent and TableStyle.Parent properties), and modify only the required characteristics.

Some styles can act as a paragraph style or a character style, depending on the range to which it is applied. Such styles are known as linked styles. If a linked style is applied to a selection that does not include an entire paragraph, the selected text is formatted with the character formatting settings of the linked style. If a selection includes an entire paragraph, both character and paragraph formatting settings are applied. If a selection is only a caret position that contains no characters, the linked style behaves like a paragraph style.

You can delete a style from the collection of styles in the document using the CharacterStyleCollection.Delete, ParagraphStyleCollection.Delete or TableStyleCollection.Delete methods. A deleted style can no longer be applied to text or saved in a document file.

Styles are inherent to the document, so you cannot add a style contained in the style collection of one document to the style collection of another document. In this case, create a new style and copy its properties, one by one. When performing mail merge, use the MailMergeOptions.CopyTemplateStyles property to copy template styles to the merged document.