Table of Contents

Method ApplyBuiltInStyle

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

ApplyBuiltInStyle(WordDocument, DocumentSpan, string)

Applies one of Word's built-in styles by name, as the Styles gallery and Ctrl+Alt+1 do (WQ-0106). The document's style of that name is used when it has one (names compared ignoring case, heading 1 as Heading 1); a style hidden until used (w:semiHidden with w:unhideWhenUsed) is unhidden, and so is its linked style. A document without one gets Word's definition from BuiltInStyles, and for a linked paragraph style its … Char character style too (or the document's character style of that name), under Word's ids, numbered when an id is taken, based on the document's default styles. A paragraph style is applied to every paragraph the span touches, a character style to the text it covers; direct formatting stays.

public static DocumentEdit ApplyBuiltInStyle(this WordDocument document, DocumentSpan span, string name)

Parameters

document WordDocument

The document.

span DocumentSpan

The selection, or a caret.

name string

The style's name: one of Names, Normal (in a document without a default paragraph style, no style), or the name of a paragraph or character style of the document.

Returns

DocumentEdit

The edit; undoing it removes the styles it added.

Exceptions

ArgumentNullException

document or name is null.

ArgumentException

The span is not in the document, or neither the document nor the library has a paragraph or character style of the name.

InvalidOperationException

An end is in a shape's text box.