Table of Contents

Method CreateStyleFromSelection

Namespace
DocWright.Dom.Editing
Assembly
DocWright.Dom.dll

CreateStyleFromSelection(WordDocument, DocumentSpan, string, bool)

Create a Style from the selection: a new paragraph style named name, based on the first paragraph's style, holding that paragraph's direct paragraph formatting and the direct run formatting at the span's start, with a linked character style (name Char) holding the same run formatting, as Word adds them. Every paragraph the span touches takes the new style, which is then reapplied to it.

public static DocumentEdit CreateStyleFromSelection(this WordDocument document, DocumentSpan span, string name, bool quickFormat = true)

Parameters

document WordDocument

The document.

span DocumentSpan

The selection, or a caret.

name string

The style's name, as the gallery shows it. Its id is the name without spaces and other characters an id does not take, with a number added when the id is taken.

quickFormat bool

Whether the style is shown in the Styles gallery (w:qFormat).

Returns

DocumentEdit

The edit; undoing it removes both styles.

Exceptions

ArgumentNullException

document or name is null.

ArgumentException

The span is not in the document, the name is empty or longer than 253 characters, or a style already has the name (as Word compares names: ignoring case).