All docs
V21.2
21.2
21.1
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Excel Data Source

  • 2 minutes to read

This tutorial shows how to add the DashboardExcelDataSource to data source storage and make it available to users. The specified cell range on the worksheet supplies the dashboard with data.

  1. In your application, add the Financial.xls file to the App_Data folder from the C:\Users\Public\Documents\DevExpress Demos 21.2\Components\Data directory.

  2. In the dashboard configuration file (for example, DashboardConfig.cs), create a public method that returns the configured dashboard’s data source storage (DataSourceInMemoryStorage) and define the Excel data source.

    using DevExpress.DashboardWeb;
    
    public static DataSourceInMemoryStorage CreateDataSourceStorage() {
        DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
    
        DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source");
        excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Current_Stocks"));
        dataSourceStorage.RegisterDataSource("excelDataSource", excelDataSource.SaveToXml());
    
        return dataSourceStorage;
    }
    
  3. Call the DashboardConfigurator.SetDataSourceStorage method to configure the data source storage. Use the created CreateDataSourceStorage method as the SetDataSourceStorage parameter and handle the DashboardConfigurator.ConfigureDataConnection event to pass the connection parameters to the Excel data source.

    using DevExpress.DashboardWeb;
    using DevExpress.DataAccess.Excel;
    
    public static void RegisterService(RouteCollection routes) {
        routes.MapDashboardRoute("dashboardControl", "DefaultDashboard");
    
        // ...
    
        DashboardConfigurator.Default.SetDataSourceStorage(CreateDataSourceStorage());        
        DashboardConfigurator.Default.ConfigureDataConnection += Default_ConfigureDataConnection;
    }
    private static void Default_ConfigureDataConnection(object sender, ConfigureDataConnectionWebEventArgs e) {
        if(e.DataSourceName.Contains("Excel Data Source")) {
            var excelParams = new ExcelDataSourceConnectionParameters(HostingEnvironment.MapPath(@"~/App_Data/_Financial.xls"));
            e.ConnectionParameters = excelParams;
        }
    }
    

The Excel Data Source is now available in the Web Dashboard:

web-dashboard-ex-object-data-source

Users can now bind dashboard items to data in the Web Dashboard’s UI.

Example

The example shows how to make a set of data sources available for users in the Web Dashboard application.

View Example: How to Register Data Sources for the ASP.NET MVC Dashboard Extension