Skip to main content

SubDocument.GetOpenXmlBytes(DocumentRange) Method

Exports the content of the specified document range as a document in Office Open XML (Docx) format and returns a byte array with this document.

Namespace: DevExpress.XtraRichEdit.API.Native

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

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

byte[] GetOpenXmlBytes(
    DocumentRange range
)

Parameters

Name Type Description
range DocumentRange

A DocumentRange object representing the range to convert to OpenXML.

Returns

Type Description
Byte[]

An array of bytes that is the document content in OpenXML format.

Remarks

You can specify export options via the RichEditDocumentExportOptions.OpenXml property in the RichEditControl.BeforeExport event handler or use another GetOpenXmlBytes method overload.

If you operate with a selection range, the GetOpenXmlBytes method should be enclosed within 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.

To retrieve the section settings, make sure that the range contains the last section’s paragraph. Otherwise, the section settings are reset to the default.

Example

This code snippet illustrates how to export the selected range to the string in DOCX (OpenXML) format.

 if (this.richEditControl.Document.Selection.Length > 0) 
{
                    DevExpress.XtraRichEdit.API.Native.DocumentRange selection = richEditControl.Document.Selection;
                    DevExpress.XtraRichEdit.API.Native.SubDocument doc = selection.BeginUpdateDocument();
                    bytes = doc.GetOpenXmlBytes(selection);
                    selection.EndUpdateDocument(doc);
                }
                else 
{
                    bytes = richEditControl.Document.GetOpenXmlBytes(richEditControl.Document.Range);
                }

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetOpenXmlBytes(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.

See Also