Workbook.LoadDocument(Stream, DocumentFormat) Method
Loads a document in the specified format from a stream.
You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use this method in production code.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Docs.v19.1.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
stream | Stream | The stream from which to load a document. |
format | DocumentFormat | A DocumentFormat enumeration member that specifies the format of the loaded document. |
Returns
Type | Description |
---|---|
Boolean | true, if a document was loaded successfully; otherwise, false. |
Remarks
If you attempt to load a document in an incorrect format, the Workbook.InvalidFormatException event fires. To throw an exception when an invalid document is loaded, set the WorkbookImportOptions.ThrowExceptionOnInvalidDocument property to true (use the Workbook.Options.Import notation to access import options).
Handle the Workbook.DocumentLoaded event to determine when you can safely modify the loaded document.
// Add a reference to the DevExpress.Docs.dll assembly.
using DevExpress.Spreadsheet;
using System.IO;
// ...
Workbook workbook = new Workbook();
// Load a workbook from the stream.
using (FileStream stream = new FileStream("Documents\\Document.xlsx", FileMode.Open)) {
workbook.LoadDocument(stream, DocumentFormat.Xlsx);
}
The LoadDocument method can use a non-seekable stream to load a document. In this case, the stream is copied to a memory stream for further processing.
Note
If you use the DocumentFormat.Undefined value as the method’s format parameter, the document’s format is detected automatically.
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the LoadDocument(Stream, DocumentFormat) 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.