Back to Devexpress

SubDocument.GetText(DocumentRange) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-dot-gettext-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentrange-x29.md

latest8.3 KB
Original Source

SubDocument.GetText(DocumentRange) Method

Returns the plain text of the specified document range.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
string GetText(
    DocumentRange range
)
vb
Function GetText(
    range As DocumentRange
) As String

Parameters

NameTypeDescription
rangeDocumentRange

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

|

Returns

TypeDescription
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:

EventDescription
RichEditControl.BeforeExportAllows you to specify options for plain text export (defined by the PlainTextDocumentExporterOptions instance).
RichEditControl.AfterExportDoes 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

View Example

csharp
DevExpress.XtraRichEdit.API.Native.Document document = server.Document;
document.LoadDocument("Documents\\Grimm.docx", DocumentFormat.Docx);
string plainText = document.GetText(document.Paragraphs[2].Range);
System.Windows.Forms.MessageBox.Show(plainText);
vb
Dim document As DevExpress.XtraRichEdit.API.Native.Document = server.Document
document.LoadDocument("Documents\Grimm.docx", DocumentFormat.Docx)
Dim plainText As String = document.GetText(document.Paragraphs(2).Range)
System.Windows.Forms.MessageBox.Show(plainText)

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.

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/SearchAndReplace.cs#L23

csharp
{
    sixLetterWords.Add(document.GetText(r));
}

winforms-richeditcontrol-common-api/CS/RichEditAPISample/CodeExamples/RichEditControlActions.cs#L336

csharp
string currentToolTipText = String.Format("Position: {0}, Character: {1}", pos.ToString(),
    richEdit.Document.GetText(richEdit.Document.CreateRange(pos, 1)));

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/SearchAndReplaceActions.cs#L23

csharp
{
    sixLetterWords.Add(document.GetText(r));
}

winforms-richedit-layout-api-practical-usage/CS/WindowsFormsApplication1/DocumentLayoutHelper/TextBoxLayoutHelper.cs#L55

csharp
SubDocument doc = currentLayout.BeginUpdateDocument(currentTextBox);
string plainTextContent = doc.GetText(doc.Range);
currentLayout.EndUpdateDocument(doc);

word-document-api-examples/CS/CodeExamples/FieldActions.cs#L57

csharp
// Access a field code.
string fieldCode = document.GetText(document.Fields[i].CodeRange);

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/SearchAndReplace.vb#L19

vb
For Each r As DevExpress.XtraRichEdit.API.Native.DocumentRange In found
    sixLetterWords.Add(document.GetText(r))
Next

winforms-richeditcontrol-common-api/VB/RichEditAPISample/CodeExamples/RichEditControlActions.vb#L345

vb
Dim currentToolTipText As String = String.Format("Position: {0}, Character: {1}", pos.ToString(),
                                                 richEdit.Document.GetText(richEdit.Document.CreateRange(pos, 1)))

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/SearchAndReplaceActions.vb#L17

vb
For Each r As DocumentRange In found
    sixLetterWords.Add(document.GetText(r))
Next r

winforms-richedit-layout-api-practical-usage/VB/WindowsFormsApplication1/DocumentLayoutHelper/TextBoxLayoutHelper.vb#L60

vb
Dim doc As SubDocument = currentLayout.BeginUpdateDocument(currentTextBox)
Dim plainTextContent As String = doc.GetText(doc.Range)
currentLayout.EndUpdateDocument(doc)

word-document-api-examples/VB/CodeExamples/FieldActions.vb#L49

vb
' Access a field code.
Dim fieldCode As String = document.GetText(document.Fields(CInt((i))).CodeRange)
' Check whether a field code is "DATE".

See Also

RichEditControl Events

SubDocument Interface

SubDocument Members

DevExpress.XtraRichEdit.API.Native Namespace