Workbook.LoadDocument(Stream) Method
Loads a document from a stream.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Docs.v19.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
stream | Stream | The stream from which to load a document. |
Returns
Type | Description |
---|---|
Boolean | true, if a document was loaded successfully; otherwise, false. |
Remarks
The Spreadsheet uses the built-in IFormatDetectorService service implementation to detect the loaded document’s format. The following formats can be detected:
- XLSX, XLSB, XLSM, XLTX, XLTM (non-encrypted files only)
- XLS, XLT
- CSV, TXT (only if a file is loaded from a FileStream instance).
If format detection fails, the Workbook.InvalidFormatException event fires.
You can pass a non-seekable stream (a stream that does not support the Seek operation, for instance, a NetworkStream) to the LoadDocument method. In this case, the stream is copied to a memory stream to load a document.
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);
}