Skip to main content
A newer version of this page is available. .

How to: Export Range To Different Formats

  • 2 minutes to read

The following example describes how to export document range to different formats.

RcihEditDocumentServer provides a number of methods, allowing you to retrieve contents of the specified range in different formats. These are:

To retrieve the document range into plane text, use the SubDocument.GetText, as illustrated below.

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

The SubDocument.GetHtmlText is used to export range contents into HTML format. The following code demonstrates how to retrieve range into HTML format and open the resulting document in the browser windows:

DevExpress.XtraRichEdit.API.Native.Document document = server.Document;
document.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
// Get the range for three paragraphs.
DocumentRange r = document.CreateRange(document.Paragraphs[0].Range.Start, document.Paragraphs[0].Range.Length + document.Paragraphs[1].Range.Length + document.Paragraphs[2].Range.Length);
// Export to HTML.
string htmlText = document.GetHtmlText(r, null);
System.IO.File.WriteAllText("test.html", htmlText);
// Show the result in a browser window.
System.Diagnostics.Process.Start("test.html");