Document Import and Export
- 3 minutes to read
TdxRichEditControl and TdxRichEditDocumentServer components allow you to import/export document content to/from a file or stream in a format of your choice: RTF, TXT, DOCX, HTML, and DOC.
Document Import and Export APIs
Both TdxRichEditControl and TdxRichEditDocumentServer components implement similar API members designed for document import and export in supported formats.
Important
Ensure that support for all required document formats is enabled; otherwise, an exception occurs. Both components include dedicated import and export settings (for each supported document format).
Refer to the following topic section for details: Enable Support for Individual Document Formats.
Rich Edit Control
TdxRichEditControl declares the following methods designed for content import and export:
- LoadDocument
- Imports document content from a file or stream (in any supported format).
- LoadDocumentTemplate
- Imports a document as a template from a file or stream (in any supported format).
- SaveDocument
- Exports document content to a file or stream (in any supported format).
Document Server
TdxRichEditDocumentServer declares the following properties and methods designed for content import and export:
- DocBytes
- Specifies document content as a byte array (in the Microsoft Word® 97 – 2003 binary format).
- HtmlText
- Specifies document content as a string (in the HTML format).
- OpenXmlBytes
- Specifies document content as a byte array (in the Office OpenXML format).
- RtfText
- Specifies document content (as an RTF string).
- Text
- Specifies document content (as a plain text string).
- LoadDocument | LoadDocumentTemplate | SaveDocument
- Export/import document content to/from a file or stream in any supported format.
Enable Support for Individual Document Formats
DevExpress Rich Text components initially support a limited number of document formats to avoid excessive dependencies:
- TdxRichEditControl
- Has predefined support only for TXT and RTF.
- TdxRichEditDocumentServer
- Has predefined support only for TXT.
To enable support for all available formats, add all required dependencies at design time or in code:
Extension | Document Format | Format Value | Import/Export Settings | Support / Required Dependencies |
---|---|---|---|---|
TXT /txt |
Plain Text | PlainText | Options.Import.PlainText/Options.Export.PlainText | Built-in Support |
RTF /rtf |
Rich Text Format | Rtf | Options.Import.Rtf/Options.Export.Rtf | dxRichEdit.Rtf (add only for TdxRichEditDocumentServer) |
DOC /doc |
Microsoft Word® 97 – 2003 | Doc | Options.Import.Doc/Options.Export.Doc | dxRichEdit.Doc |
HTML /html |
Hypertext Markup Language | Html | Options.Import.Html/Options.Export.Html | dxRichEdit.Html |
DOCX /docx |
Office OpenXML | OpenXml | Options.Import.OpenXml/Options.Export.OpenXml | dxRichEdit.OpenXML |
At design time, you can right-click a TdxRichEditControl or TdxRichEditDocumentServer component, expand the Add Unit to Support menu item, and add all required dependencies.
HTML Support Limitations and Considerations
TdxRichEditControl and TdxRichEditDocumentServer components have no HTML editor functionality because they do not work with HTML tags directly. HTML import routines interpret tags in a source document and build an internal document model according to the current import settings.
Important
HTML import and export routines support only a limited subset of the modern HTML standard – imported and exported documents may look different compared to corresponding source documents.
Related Compiled Demo
To see the Rich Edit import and export functionality in action, run the Word Processing RTF demo in the VCL Demo Center installed with compiled DevExpress demos. Click the Open or Save As button to open the corresponding dialog.
Tip
Compiled DevExpress demos ship with source code installed in the Public Documents folder (%Public%) for all users (default). You can find all project and source code files for the Rich Edit control demo in the following folder:
%Public%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressRichEditControl