dashboard-116654-web-dashboard-integrate-dashboard-component-dashboard-backend-prepare-data-source-storage-for-the-aspnet-core-framework-excel-data-source.md
This topic shows how to add the DashboardExcelDataSource to an in-memory data source storage, and make it available to users. The specified cell range on the defined worksheet supplies the dashboard with data.
Add an Excel workbook or CSV file (.xls, .xlsx, or .csv formats) to your project.
This example uses the Sales.xlsx file. You can find other sample datasets in the following directory:
C:\Users\Public\Documents\DevExpress Demos 25.2\Components\Data
To create an Excel Data Source, follow the steps below:
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using DevExpress.DataAccess.Excel;
DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source");
excelDataSource.ConnectionName = "excelDataConnection";
excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Sheet1"));
configurator.ConfigureDataConnection += (s, e) => {
if (e.ConnectionName == "excelDataConnection") {
ExcelDataSourceConnectionParameters excelParameters = (ExcelDataSourceConnectionParameters)e.ConnectionParameters;
excelParameters.FileName = fileProvider.GetFileInfo("Data/Sales.xlsx").PhysicalPath;
}
};
Call the DataSourceInMemoryStorage.RegisterDataSource method to register the data source in the data source storage. Call the DashboardConfigurator.SetDataSourceStorage to specify the data source storage for the Web Dashboard.
// Create a data source storage.
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
// Register the Excel data source.
dataSourceStorage.RegisterDataSource("excelDataSource", excelDataSource.SaveToXml());
// Register the storage for the Web Dashboard.
configurator.SetDataSourceStorage(dataSourceStorage);
The Excel Data Source is now available in the Web Dashboard:
Users can bind dashboard items to data in the Web Dashboard’s UI.
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 ASP.NET Core Dashboard Control