Method ReplaceRange
ReplaceRange(WordDocument, DocumentSpan, string, CharacterFormat?)
Replaces a span with text as one edit, as typing over a selection or an input-method commit does. Across paragraphs the two ends are joined, keeping the first paragraph's properties (the last's when the span starts at the first's beginning). A span that ends at the very start of a later paragraph leaves that paragraph alone, as Word does. The text takes the formatting of the first character the span covers.
public static DocumentEdit ReplaceRange(this WordDocument document, DocumentSpan span, string text, CharacterFormat? format = null)
Parameters
documentWordDocumentThe document that holds the span.
spanDocumentSpanThe span.
textstringThe text, under InsertText(WordDocument, DocumentPosition, string, CharacterFormat?)'s rules.
formatCharacterFormatThe text's formatting, or null for the first covered character's.
Returns
- DocumentEdit
The edit; After is just past the inserted text.
Exceptions
- ArgumentNullException
documentortextis null.- ArgumentException
As InsertText(WordDocument, DocumentPosition, string, CharacterFormat?) and DeleteRange(WordDocument, DocumentSpan).
- InvalidOperationException
As InsertText(WordDocument, DocumentPosition, string, CharacterFormat?) and DeleteRange(WordDocument, DocumentSpan).