Method InsertText
InsertText(WordDocument, DocumentPosition, string, CharacterFormat?)
Inserts text at a position. A \t becomes a tab, a \v a line break, and
\r\n, \n or \r a paragraph split, as plain-text paste does.
public static DocumentEdit InsertText(this WordDocument document, DocumentPosition at, string text, CharacterFormat? format = null)
Parameters
documentWordDocumentThe document that holds the position.
atDocumentPositionWhere to insert.
textstringThe text.
formatCharacterFormatThe text's formatting, or null for the formatting Word gives typed text there.
Returns
- DocumentEdit
The edit; After is just past the inserted text.
Exceptions
- ArgumentNullException
documentortextis null.- ArgumentException
The position is not in
document, falls inside a surrogate pair, or the text holds a control character other than tab, vertical tab and line endings, a non-character, or an unpaired surrogate.- ArgumentOutOfRangeException
The position's offset is outside its paragraph's content.
- InvalidOperationException
The text holds a line ending and the position is inside an inline content control, or the position is inside content a reader synthesized.