SubDocument.GetText(DocumentRange) Method
Returns the plain text of the specified document range.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v18.2.Core.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
range | DocumentRange | A DocumentRange object, specifying the range in the document for which the plain text representation is obtained. |
Returns
Type | Description |
---|---|
String | A String value, containing the text of the specified range. |
Remarks
Use the GetText method to get a plain text of any part of the document. This method overload triggers export-related events as described in the following table:
Event | Description |
---|---|
RichEditControl.BeforeExport | Allows you to specify options for plain text export (defined by the PlainTextDocumentExporterOptions instance). |
RichEditControl.AfterExport | Does not occur. |
Note
If you operate with a selection range, the GetText method should be combined with a DocumentRange.BeginUpdateDocument - DocumentRange.EndUpdateDocument method pair. Otherwise, an incorrect document model might be selected, resulting in an exception “Error: specified document position or range belongs to other document or subdocument” being thrown.
Example
This code snippet switches to the document footer to select the first paragraph of the footer content.
Subsequently, the SubDocument.GetText method obtains the selection as plain text.
Note that the GetText method is combined with the DocumentRange.BeginUpdateDocument - DocumentRange.EndUpdateDocument method pair to ensure that the GetText method uses a correct document model.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/winforms-richedit-document-api-e5219
document.LoadDocument("FloatingObjects.docx", DocumentFormat.OpenXml)
' Select footer.
Dim footerDocument As SubDocument = document.Sections(0).BeginUpdateFooter()
document.ChangeActiveDocument(footerDocument)
document.Selection = footerDocument.Paragraphs(0).Range
document.Sections(0).EndUpdateFooter(footerDocument)
' Get selection as plain text.
Dim docRange As SubDocument = document.Selection.BeginUpdateDocument()
Dim plainText As String = docRange.GetText(docRange.Range)
document.Selection.EndUpdateDocument(docRange)
DevExpress.XtraEditors.XtraMessageBox.SmartTextWrap = True
DevExpress.XtraEditors.XtraMessageBox.Show(plainText)
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the GetText(DocumentRange) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.