Skip to main content
A newer version of this page is available. .

How to: Load a Document into SpreadsheetControl

  • 2 minutes to read

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 in XAML

    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>
    
  • Load from File

    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 from Stream

    Create a FileStream object with the specified file path to open the existing file, and 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);
    }