Skip to main content

IdxRichEditDocument.LoadDocument(string,TdxRichEditDocumentFormat) Method

Imports a document from the specified file.

Declaration

procedure LoadDocument(const AFileName: string; AFormat: TdxRichEditDocumentFormat); overload;

Parameters

Name Type Description
AFileName string

An absolute or relative path to a source document file.

AFormat TdxRichEditDocumentFormat

A document format.

Remarks

Call the LoadDocument procedure to import a document from a file in any supported format. Imported content replaces the current document.

If the AFormat parameter accepts the TdxRichEditDocumentFormat.Undefined value, the procedure detects the target format by the file name extension. If the file name has no extension, the LoadDocument procedure iterates through all supported document formats to find the best possible match in the target file’s content.

A successful LoadDocument call updates Options.DocumentSaveOptions.CurrentFileName and Options.DocumentSaveOptions.CurrentFormat property values for the parent TdxRichEditControl or TdxRichEditDocumentServer component.

Source Document Format Detection

Use the AFormat parameter to specify the source document format.

If you pass TdxRichEditDocumentFormat.Undefined as the AFormat parameter, the LoadDocument procedure uses the source file name extension to identify the target format. If the file name has no extension, LoadDocument iterates through all supported formats to find the best possible match for the source document.

Import Format Support

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.

VCL Rich Edit Control: Add Supported Document Formats at Design Time

Other Import/Export Options

You can also use the following API members to import/export document content in different supported[1] formats:

DocBytes
Specifies document content as a byte array (in the Microsoft Word® 97 – 2003 binary 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 | SaveDocument
Export/import document content to/from file or stream in any supported format.
Footnotes
  1. Ensure that support for all required document formats is enabled; otherwise, an exception occurs.
    Refer to corresponding API member descriptions for detailed information on support for different document formats.

See Also