Binding to Microsoft Excel Workbooks

The Dashboard Designer allows you to select required data from Microsoft Excel workbooks (XLS, XLSX or XLSM). You can select all data from the specified worksheet or you can select the cell range referenced by the specified defined/table name.

Creating a Data Source in the Data Source Wizard

To bind a dashboard to a Microsoft Excel workbook, do the following.

  1. Click the New Data Source button in the Data Source ribbon tab.

    DataBinding_NewDataSource

  2. On the first page of the invoked Data Source Wizard dialog, select Microsoft Excel workbook / CSV file and click Next.

    DataSourceWizard_DataSourceType_Excel

  3. On the next page, locate the required workbook by clicking an ellipsis button and selecting the file.

    DataSourceWizard_SelectExcelFile

    Click Next.

    Note

    If the workbook is protected by a password, the following window will be invoked.

    DataSourceWizard_ProtectedExcelWorkbook

    Specify a password in the Password field and click OK. Note that if you enable the Save password flag, the password will be saved to a dashboard definition as plain text.

  4. Then, specify import settings used to extract data from the workbook.

    DataSourceWizard_SpecifyImportSettings

    The following options can be specified.

    • Use values of the first row as field names - Specifies whether to use the values of the first row as field names. If you disable this option, field names will be generated automatically.
    • Skip empty rows - Specifies whether or not to include the empty rows into the resulting data source.
    • Skip hidden rows - Specifies whether to ignore hidden rows when importing data to a data source.
    • Skip hidden columns - Specifies whether to ignore hidden columns when importing data to a data source.

    Click Next.

  5. On the next page, you can select the worksheet containing the required data, the table or the defined name referring to the specified cell range.

    DataSourceWizard_SelectDefinedName

    Click Next.

  6. On the final page, you can select columns to be included to a data source and specify their settings. The Name column allows you to specify the column name while Type allows you to specify its type.

    DataSourceWizard_SpecifyColumnSettings

    Click Finish to create a data source. This creates the data source and displays its fields in the Data Source Browser.

Creating a Data Source in Code

The DashboardExcelDataSource class allows you to extract data from Microsoft Excel workbooks (XLS, XLSX or XLSM) or CSV files stored on the disk or stream.

To extract data from the specified workbook or CSV file, do the following.

Finally, add the created DashboardExcelDataSource object to the Dashboard.DataSources collection.

The following code snippet shows how to create an Excel data source and select the A1:L100 range of cells located on the SalesPerson worksheet.

using DevExpress.DashboardCommon;
using DevExpress.DataAccess.Excel;
// ... 
            Dashboard dashboard = new Dashboard();
            DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource();
            excelDataSource.FileName = @"c:\temp\Book1.xlsx";
            ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("SalesPerson", "A1:L100");
            excelDataSource.SourceOptions = new ExcelSourceOptions(worksheetSettings);
            excelDataSource.Fill();
            dashboard.DataSources.Add(excelDataSource);