The requested page is not available for the requested platform. You are viewing the content for Default platform.

Connect the ASP.NET Core Dashboard to an Excel Database

  • 2 min to read

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

  1. In your application, create the Data folder and add the Financial.xls file to it from the following folder:

    C:\Users\Public\Documents\DevExpress Demos 19.2\Components\Data

  2. In the Startup.cs file, create a public method that returns a configured in-memory dashboard data source storage (DataSourceInMemoryStorage) and define the Excel data source.

    using DevExpress.DashboardCommon;
    using DevExpress.DataAccess.Excel;
    
    public DataSourceInMemoryStorage CreateDataSourceStorage() {
        DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
    
        DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source");
              excelDataSource.FileName = Path.Combine(HostingEnvironment.ContentRootPath, @"Data\Financial.xlsx");
              excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Current_Stocks"));
              dataSourceStorage.RegisterDataSource("excelDataSource", excelDataSource.SaveToXml());      
    
        return dataSourceStorage;
    }
    
    Note

    Use the IHostingEnvironment.ContentRootPath property to set the absolute path to the directory that contains the database.

  3. Call the DashboardConfigurator.SetDataSourceStorage method to configure the data source storage. Use the created CreateDataSourceStorage method as the SetDataSourceStorage parameter.

    using DevExpress.AspNetCore;
    using DevExpress.DashboardAspNetCore;
    using DevExpress.DashboardWeb;
    
    public void ConfigureServices(IServiceCollection services) {            
        services
            .AddMvc()
            .AddDefaultDashboardController(configurator => {
                // ...
                configurator.SetDataSourceStorage(CreateDataSourceStorage());
            });
    }
    
  4. As a result, the Excel Data Source is displayed as a Web Dashboard's predefined data source.

    web-dashboard-ex-core-excel-data-source

    End users can now bind the dashboard items to data in the Web Dashboard's UI. See Binding Dashboard Items to Data in the Web Dashboard's UI for more information.

Example

The example displays how to provide a Web Dashboard with a set of predefined data sources available for end users.