Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Collapse]Data Binding Common Concepts
    How to: Bind GridControl to Database and Implement Master-Detail Mode at Design Time
    How to: Bind a Control to a Database at Runtime
    How to: Bind a Control to Data Created at Runtime
    How to: Bind a Control to Data in an XML File
    Traditional Data Binding Methods
    Data Source Configuration Wizard
    Data Binding Mechanism in ADO.NET
    Binding Controls to XML Data
    Binding Controls to Data Created at Runtime
    Add Unbound Data to a Data-Aware Control (XtraGrid, XtraPivotGrid)
    Binding to Excel Data Sources
    Binding to LINQ to SQL Classes
    Unbound Sources
    Binding to Entity Framework Core
    Binding to OData
    Binding to SQL Data
    Data Annotation Attributes
    How to: Add Virtual Rows Using the UnboundSource Component
    Obtaining Fields Available in Data Source
  [Expand]Data Source Wizard
  [Expand]Expressions
  [Expand]Behaviors
  [Expand]Application Appearance
  [Expand]Filtering UI Context
  [Expand]High DPI Support
  [Expand]Scaffolding Wizard
  [Expand]Formatting Values
   HTML Text Formatting
  [Expand]Menus
  [Expand]Tooltip Management
  [Expand]Saving and Restoring Layouts
   Clipboard - Copy and Paste Operations. Data Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Binding to Excel Data Sources

This document illustrates how to bind to data from Microsoft Excel workbooks (XLS, XLSX or XLSM files) or CSV files using the Data Source Configuration Wizard, the ExcelDataSource component and in code.

Expanded Data Source Configuration Wizard

  1. Invoke the smart tag for the required data-aware DevExpress control and select the 'Data Source Wizard' option.

  2. On the wizard main page, select the 'Excel Data Source' option. Click 'New Data Source' to create a new data source or select the required data source from the list, then click 'Next' to proceed.

  3. Select the required data source and set advanced options using the Data Source Wizard. The following gallery illustrates this process.

  4. Click finish and run the application to see the result.

Expanded The ExcelDataSource Component

Using the ExcelDataSource component, you can provide data from Excel data sources for any data-aware control that does not support the Data Source Configuration Wizard.

  1. Locate the ExcelDataSource component on the toolbox under the 'Data&Analytics' group and drop it onto your form.

  2. When you add the ExcelDataSource component to an application form, the 'Data Source Wizard' dialog automatically pops up. Follow these steps to set up the connection. To invoke this wizard manually, use the component's smart-tag as shown below.

  3. Assign the customized ExcelDataSource component as the data source for the target control. For instance, for the Data Grid control, use the GridControl.DataSource property.

  4. The ExcelDataSource component does not retrieve records automatically. Thus, to populate your data control, call the Fill method as the code below shows.

Expanded Binding in Code

  1. Create a new instance of the ExcelDataSource component.
  2. Use the ExcelDataSource.FileName or ExcelDataSource.Stream properties to supply the component with a data source from a local storage or stream.
  3. Depending on the data source type (Excel workbook or CSV file), create either a ExcelSourceOptions or CsvSourceOptions object. Using this object's properties, you can specify a cell range to be loaded. Assign the object created to the ExcelDataSource.SourceOptions property.
    Important

    You must provide the ExcelWorksheetSettings, ExcelTableSettings or ExcelDefinedNameSettings objects for each ExcelSourceOptions class instance.

  4. Set additional import options if required.
  5. Assign your ExcelDataSource to the data-aware control and call the component's Fill method to populate it with records.
  6. The complete code is listed below.

How would you rate this topic?​​​​​​​