DashboardExcelDataSource Class
A data source used to extract data from Microsoft Excel workbooks or CSV files.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v20.2.Core.dll
NuGet Packages: DevExpress.Dashboard.Core, DevExpress.WindowsDesktop.Dashboard.Core
Declaration
public class DashboardExcelDataSource :
ExcelDataSource,
IDashboardDataSource,
IDashboardComponent,
IComponent,
IDisposable,
ISupportInitialize,
ISupportPrefix,
IDashboardDataSourceInternal,
IFederationDataProvider
Remarks
The DashboardExcelDataSource class allows you to extract data from Microsoft Excel workbooks (XLS, XLSX or XLSM files) or CSV files stored on the disk or stream.
To extract data from the specified workbook or CSV file, do the following.
- Assign the path to the required file using the ExcelDataSource.FileName property. As an alternative, load the required document from a stream using the ExcelDataSource.Stream property. In this case, you need to specify the required file format using the ExcelDataSource.StreamDocumentFormat property.
- Depending on the target file format, create the ExcelSourceOptions or CsvSourceOptions class instance, specify its settings and assign the resulting object to the ExcelDataSource.SourceOptions property.
- Use the ExcelDataSource.Fill method to fill the created data source with data.
Finally, add the created DashboardExcelDataSource object to the Dashboard.DataSources collection.
The following code snippet shows how to create an Excel data source that gets data from the A1:L100 range of cells located on the Data worksheet in the SalesPerson.xlsx workbook.
using DevExpress.DashboardCommon;
//...
DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource()
{
FileName = "SalesPerson.xlsx",
SourceOptions = new DevExpress.DataAccess.Excel.ExcelSourceOptions(
new DevExpress.DataAccess.Excel.ExcelWorksheetSettings()
{
WorksheetName = "Data",
CellRange = "A1:L100"
}
)
};
excelDataSource.Fill();
The following code snippet shows how to create an Excel data source and select the A1:L100 range of cells from the specified CSV file.
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.Excel;
// ...
Dashboard dashboard = new Dashboard();
DashboardExcelDataSource csvDataSource = new DashboardExcelDataSource();
csvDataSource.FileName = @"c:\temp\SalesPerson.csv";
csvDataSource.SourceOptions = new CsvSourceOptions() { CellRange = "A1:L100" };
csvDataSource.Fill();
dashboard.DataSources.Add(csvDataSource);