Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

WordStyleCollection

OfficeIMO.Word

Namespace
OfficeIMO.Word
Assembly
OfficeIMO.Word
Source revision
0eef6a5756b9 with working tree changes
Implements
IEnumerable<WordStyle> IEnumerable
Modifiers
sealed
Attributes
DefaultMember("Item")

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

Methods

public WordStyle AddCharacterStyle(string styleId, string? name = null) #

Adds a character style, based on the document's default character style.

Parameters

styleId string required
The identifier paragraphs store to use the style.
name string? = null optional
The name shown in Word; defaults to styleId.

Returns

WordStyle The new style, ready to configure.

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 required
The identifier paragraphs store to use the style.
name string? = null optional
The name shown in Word; defaults to styleId.

Returns

WordStyle The new style, ready to configure.

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 required
The identifier paragraphs store to use the style.
name string? = null optional
The name shown in Word; defaults to styleId.

Returns

WordStyle The new style, ready to configure.

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 required

Returns

bool
public WordStyle? Get(string styleIdOrName) #

Finds a style by identifier, or by name when no identifier matches. Names ignore case.

Parameters

styleIdOrName string required

Returns

WordStyle? The style, or null when the document defines none.
public IEnumerator<WordStyle> GetEnumerator() #

Returns an enumerator over the document's styles in document order.

Returns

IEnumerator<WordStyle>
GetOrAdd 2 overloads
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 required

Returns

WordStyle
public WordStyle GetOrAdd(WordTableStyle style) #

Returns the document's definition of a built-in table style, adding OfficeIMO's definition first when the document has none. A definition the document already has is never replaced.

Parameters

style OfficeIMO.Word.WordTableStyle required

Returns

WordStyle
public 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 required
The document or template to copy from. It is not changed; a read-only load is enough.
conflictMode OfficeIMO.Word.WordStyleConflictMode = KeepTarget optional
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 optional
Identifiers of the styles to copy; null copies every style.

Returns

WordStyleImportReport Which styles were added, replaced, kept or renamed.

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 required

Returns

bool true when the style existed and was removed.

Exceptions

  • InvalidOperationException – The style is the default style of its type.

Properties

public int Count { get; } #

Gets the number of styles the document defines.

public WordStyle this[string styleId] { get; } #

Gets a style by identifier.

Parameters

styleId string required

Exceptions

  • KeyNotFoundException – The document defines no style with this identifier.