Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

Workbook.LoadDocument(Stream) Method

Loads a document from a stream.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Docs.v19.1.dll

Declaration

public bool LoadDocument(
    Stream stream
)

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 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.

The Spreadsheet uses the built-in IFormatDetectorService service implementation to detect the format of the loaded document. The following formats can be detected:

  • XLSX, XLSM, XLTX, XLTM (non-encrypted files only)
  • XLS, XLT
  • CSV, TXT (only if a file is loaded from a FileStream instance).

If the format detection fails, the Workbook.InvalidFormatException event fires.

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);
}
See Also