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

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

public bool LoadDocument(
    Stream stream,
    DocumentFormat format
)

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.

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.

See Also