wpf-16305-controls-and-libraries-spreadsheet-examples-files-how-to-load-a-document-into-spreadsheet-control.md
To load an existing spreadsheet document into SpreadsheetControl, use the SpreadsheetControl.LoadDocument method of the control, or the ISpreadsheetComponent.LoadDocument method of the IWorkbook object. These methods enable you to load a document from a file or a stream.
The SpreadsheetControl.BeforeImport event is raised before the document is loaded. The SpreadsheetControl.DocumentLoaded event is raised after the document is loaded.
Load a document into the SpreadsheetControl in XAML using the SpreadsheetControl.DocumentSource property. You can load documents from a stream, byte array or any other location specified by the full file path or URI. An empty document is created if the SpreadsheetControl.DocumentSource property is null.
<Grid>
<dxsps:SpreadsheetControl CommandBarStyle="Ribbon" ShowFormulaBar="True" DocumentSource="pack://application:,,,/WpfSpreadsheet;component/Document.xlsx"/>
</Grid>
Call the ISpreadsheetComponent.LoadDocument method of the IWorkbook object with the passed file path to load a workbook from the existing file. Specify the file format as the second parameter of the method using the DocumentFormat enumerator.
// Load a workbook from a file.
workbook.LoadDocument("Documents\\Document.xlsx", DocumentFormat.Xlsx);
' Load a workbook from a file.
workbook.LoadDocument("Documents\Document.xlsx", DocumentFormat.Xlsx)
Create a FileStream object with the specified file path to open the existing file. Call the ISpreadsheetComponent.LoadDocument method of the IWorkbook object with this stream object passed as a parameter. Specify the file format as the second parameter of the method using the DocumentFormat enumerator.
using System.IO;
using DevExpress.Spreadsheet;
// ...
IWorkbook workbook = spreadsheetControl1.Document;
// Load a workbook from a stream.
using (FileStream stream = new FileStream("Documents\\Document.xlsx", FileMode.Open)) {
workbook.LoadDocument(stream, DocumentFormat.Xlsx);
}
Imports System.IO
Imports DevExpress.Spreadsheet
' ...
Dim workbook As IWorkbook = spreadsheetControl1.Document
' Load a workbook from a stream.
Using stream As New FileStream("Documents\Document.xlsx", FileMode.Open)
workbook.LoadDocument(stream, DocumentFormat.Xlsx)
End Using