SubDocument.GetText(DocumentRange, PlainTextDocumentExporterOptions) Method
Returns the plain text of the specified document range.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v20.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. |
options | PlainTextDocumentExporterOptions | A PlainTextDocumentExporterOptions instance, containing options for plain text export. |
Returns
Type | Description |
---|---|
String | A String value, containing the text of the specified range. |
Remarks
Use this 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 | 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, including field codes. The SubDocument.GetText method overload is used for this purpose. It allows you to set the PlainTextDocumentExporterOptions settings to include field codes and specify field enclosing symbols.
document.LoadDocument("SampleTOC.docx", DocumentFormat.OpenXml);
string plainText = String.Empty;
foreach (Field item in document.Fields)
{
string fieldCode = document.GetText(item.CodeRange);
string[] fieldParts = fieldCode.Split(' ');
if (fieldParts[0].Trim() == "TOC" && fieldParts[1].Trim() == "\\h")
{
DevExpress.XtraRichEdit.Export.PlainTextDocumentExporterOptions exportOptions =
new DevExpress.XtraRichEdit.Export.PlainTextDocumentExporterOptions();
exportOptions.ExportHiddenText = true;
exportOptions.FieldCodeStartMarker = "[<";
exportOptions.FieldCodeEndMarker = ">";
exportOptions.FieldResultEndMarker = "]";
plainText = document.GetText(item.Range, exportOptions);
}
}