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

How to: Load a Document to a Workbook

  • 2 minutes to read

Important

The Workbook class is defined in the DevExpress.Docs.v19.1.dll assembly. Add this assembly to your project to use the workbook functionality. You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use this assembly in production code. Refer to the DevExpress Subscription page for pricing information.

To load an existing spreadsheet document into the Workbook object, use the Workbook.LoadDocument method.

  • Load from File

    Create a new Workbook object and call the Workbook.LoadDocument method 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.

    // Add a reference to the DevExpress.Docs.dll assembly.
    using DevExpress.Spreadsheet;
    // ...
    
    Workbook workbook = new Workbook();
    
    // Load a workbook from the file.
    workbook.LoadDocument("Documents\\Document.xlsx", DocumentFormat.Xlsx);
    
  • Load from Stream

    Create the FileStream object with the specified file path to open the existing file, and call the Workbook.LoadDocument method with this stream object passed as a parameter. Specify the file format as the second parameter of the method using the DocumentFormat enumerator.

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