The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

SubDocument.GetText(DocumentRange, TextFragmentOptions) Method

Returns the plain text of the specified document range.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v19.2.Core.dll

Declaration

string GetText(
    DocumentRange range,
    TextFragmentOptions getTextOptions
)
Function GetText(
    range As DocumentRange,
    getTextOptions As TextFragmentOptions
) As String
string GetText(
    DocumentRange range,
    TextFragmentOptions getTextOptions
)
Function GetText(
    range As DocumentRange,
    getTextOptions As TextFragmentOptions
) As String
string GetText(
    DocumentRange range,
    TextFragmentOptions getTextOptions
)
Function GetText(
    range As DocumentRange,
    getTextOptions As TextFragmentOptions
) As String

Parameters

Name Type Description
range DocumentRange

A DocumentRange object, specifying the range in the document for which the plain text representation is obtained.

getTextOptions TextFragmentOptions

A TextFragmentOptions object.

Parameters

Name Type Description
range DocumentRange

A DocumentRange object, specifying the range in the document for which the plain text representation is obtained.

getTextOptions TextFragmentOptions

A TextFragmentOptions object.

Parameters

Name Type Description
range DocumentRange

A DocumentRange object, specifying the range in the document for which the plain text representation is obtained.

getTextOptions TextFragmentOptions

A TextFragmentOptions object.

Returns

Type Description
String

A String value, containing the text of the specified range.

Returns

Type Description
String

A String value, containing the text of the specified range.

Returns

Type Description
String

A String value, containing the text of the specified range.

Remarks

Use the GetText method to get a plain text representation of any part of the document. This method overload triggers export-related events as described in the following table:

Event Description
RichEditControl.BeforeExport Does not occur.
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.

Examples

This code snippet finds the first table of contents which is built upon Heading styles using the TOC field and converts it to plain text paragraph by paragraph. The SubDocument.GetText method overload is used for this purpose. It allows you to set the TextFragmentOptions.AllowExtendingDocumentRange option to false to not include the entire TOC when exporting the first paragraph.

document.LoadDocument("SampleTOC.docx", DocumentFormat.OpenXml)
Dim plainText As String = String.Empty

For Each item As Field In document.Fields
    Dim fieldCode As String = document.GetText(item.CodeRange)
    Dim fieldParts() As String = fieldCode.Split(" "c)
    If fieldParts(0).Trim() = "TOC" AndAlso fieldParts(1).Trim() = "\h" Then
        Dim options As New DevExpress.XtraRichEdit.API.Native.Implementation.TextFragmentOptions()
        options.AllowExtendingDocumentRange = False
        For Each par As Paragraph In document.Paragraphs.Get(item.ResultRange)
            plainText &= document.GetText(par.Range, options)
            plainText &= Environment.NewLine
        Next par
    End If
Next item

DevExpress.XtraEditors.XtraMessageBox.SmartTextWrap = False
DevExpress.XtraEditors.XtraMessageBox.Show(plainText)
See Also