Back to Devexpress

How to: Append Text to the Paragraph

officefileapi-116822-word-processing-document-api-examples-text-how-to-append-text-to-the-paragraph.md

latest1.8 KB
Original Source

How to: Append Text to the Paragraph

  • Sep 19, 2023

The following code snippet appends text to the end of the last paragraph.

View Example

csharp
using DevExpress.XtraRichEdit.API.Native;
using System.Linq;

using (var wordProcessor = new RichEditDocumentServer())
{
  // Access a document.
  Document document = wordProcessor.Document;

  // Start to edit the document.
  document.BeginUpdate();

  // Append text
  document.AppendText("First Paragraph\nSecond Paragraph\nThird Paragraph");

  // Obtain the last paragraph's end position.
  DocumentPosition paragraphEnd = document.Paragraphs.Last().Range.End;

  // Insert text to the paragraph end.
  document.InsertText(paragraphEnd, "<<Appended to Paragraph End>>");

  // Finalize to edit the document.
  document.EndUpdate();
}
vb
Imports Microsoft.VisualBasic
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Linq

Using wordProcessor = New RichEditDocumentServer()
  ' Access a document.
  Dim document As Document = wordProcessor.Document

  ' Start to edit the document.
  document.BeginUpdate()

  ' Append text
  document.AppendText("First Paragraph" & ControlChars.Lf & "Second Paragraph" & ControlChars.Lf & "Third Paragraph")

  ' Obtain the last paragraph's end position.
  Dim paragraphEnd As DocumentPosition = document.Paragraphs.Last().Range.End

  ' Insert text to the paragraph end.
  document.InsertText(paragraphEnd, "<<Appended to Paragraph End>>")

  ' Finalize to edit the document.
  document.EndUpdate()
End Using