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 create an Excel data source in code to make it available for 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.1\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;

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

  3. Use the DashboardConfigurator.SetDataSourceStorage method to set the data source storage and pass the created CreateDataSourceStorage method to use the returned value as a parameter.

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


    End users can now bind the dashboard items to data in the Web Dashboard's UI. To learn more, see Binding Dashboard Items to Data in the Web Dashboard's UI.