Skip to main content

How to: Export Range To Different Formats

  • 2 minutes to read

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

RichEditDocumentServer 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.

View Example

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);

The SubDocument.GetHtmlText is used to export range contents into HTML format. The following code snippet retrieves the range in HTML format and opens the resulting document in the browser windows:

View Example

DevExpress.XtraRichEdit.API.Native.Document document = server.Document;
document.LoadDocument("Documents\\Grimm.docx", DocumentFormat.Docx);
// 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");
See Also