WordStyleCollection
OfficeIMO.Word
The styles defined in one WordDocument: list, inspect, create, change, remove and import paragraph, character and table styles. Every change is made in the document's own style definitions.
Inheritance
- object
- WordStyleCollection
Usage
Explore 1 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 1
- Property WordDocument.Styles
Methods
public WordStyle AddCharacterStyle(string styleId, string? name = null) #Adds a character style, based on the document's default character style.
Parameters
- styleId string
- The identifier paragraphs store to use the style.
- name string? = null
- The name shown in Word; defaults to styleId.
Exceptions
ArgumentException– The identifier or name is already in use.
public WordStyle AddParagraphStyle(string styleId, string? name = null) #Adds a paragraph style, based on the document's default paragraph style.
Parameters
- styleId string
- The identifier paragraphs store to use the style.
- name string? = null
- The name shown in Word; defaults to styleId.
Exceptions
ArgumentException– The identifier or name is already in use.
public WordStyle AddTableStyle(string styleId, string? name = null) #Adds a table style, based on the document's default table style.
Parameters
- styleId string
- The identifier paragraphs store to use the style.
- name string? = null
- The name shown in Word; defaults to styleId.
Exceptions
ArgumentException– The identifier or name is already in use.
public bool Contains(string styleId) #Returns whether the document defines a style with this identifier.
Parameters
- styleId string
Returns
boolpublic WordStyle? Get(string styleIdOrName) #Finds a style by identifier, or by name when no identifier matches. Names ignore case.
Parameters
- styleIdOrName string
public IEnumerator<WordStyle> GetEnumerator() #Returns an enumerator over the document's styles in document order.
Returns
IEnumerator<WordStyle>public WordStyle GetOrAdd(WordParagraphStyles style) #Returns the document's definition of a built-in paragraph style, adding OfficeIMO's definition first when the document has none. A definition the document already has is never replaced.
Parameters
- style OfficeIMO.Word.WordParagraphStyles
Returns
WordStylepublic WordStyleImportReport Import(WordDocument source, WordStyleConflictMode conflictMode = KeepTarget, IEnumerable<string>? styleIds = null) #Copies styles from another document, together with the styles they are based on, link to or are followed by, and the lists they number paragraphs with.
Parameters
- source OfficeIMO.Word.WordDocument
- The document or template to copy from. It is not changed; a read-only load is enough.
- conflictMode OfficeIMO.Word.WordStyleConflictMode = KeepTarget
- What to do when the target already has a style matching a requested style. Styles copied only because a requested style depends on them use the target's matching style when there is one.
- styleIds System.Collections.Generic.IEnumerable<string>? = null
- Identifiers of the styles to copy; null copies every style.
Exceptions
KeyNotFoundException– A requested identifier does not exist in source.
public bool Remove(string styleId) #Removes a style. Content that used it falls back to the default style, styles based on it inherit from its base style instead, and next-style, linked-style and list-level references to it are removed.
Parameters
- styleId string
Returns
bool true when the style existed and was removed.Exceptions
InvalidOperationException– The style is the default style of its type.
Inherited Methods
Properties
public WordStyle this[string styleId] { get; } #Gets a style by identifier.
Parameters
- styleId string
Exceptions
KeyNotFoundException– The document defines no style with this identifier.