Skip to main content

Binding to CSV Files

  • 4 minutes to read

The Dashboard Designer allows you to select data from CSV files. You can select all data from the file or you can select the required cell range using Data Access API.

Creating a Data Source in the Data Source Wizard

To bind a dashboard to a CSV file, do the following.

  1. Click the New Data Source button in the Data Source ribbon tab.

    DataBinding_NewDataSource

  2. On the first page of the invoked Data Source Wizard dialog, select the Microsoft Excel workbook / CSV file and click Next.

    DataSourceWizard_DataSourceType_Excel

  3. On the next page, locate the required CSV file by clicking the ellipsis button and selecting the file.

    DataSourceWizard_SelectCsvFile

    Click Next.

  4. Then, specify import settings used to extract data from the CSV file.

    DataSourceWizard_SpecifyImportSettingsCsv

    The following options can be specified.

    • Use values of the first row as field names - Specifies whether to use the values of the first row as field names. If you disable this option, field names will be generated automatically.
    • Skip empty rows - Specifies whether to include the empty rows into the resulting data source.
    • Trim Blanks - Specifies whether to remove all leading and trailing white-space characters from each value in the CSV document.
    • Encoding - Specifies the character encoding of the CSV document. You can use the Detect automatically option to specify whether character encoding is automatically determined.
    • Newline type - Specifies the character used to identify a new line in a CSV document. You can use the Detect automatically option to specify whether the character used to identify a new line is automatically determined.
    • Value separator - Specifies a character used to separate values in a CSV document. You can use the Detect automatically option to specify whether the character used to separate values in a CSV document is determined automatically.
    • Culture - Specifies the culture information used to parse the data being imported.
    • Text Qualifier - Specifies the character that encloses values in the CSV document.

    Click Next.

  5. On the final page, you can select columns to be included to a data source and specify their settings. The Name column allows you to specify the column name while Type allows you to specify its type.

    DataSourceWizard_SpecifyColumnSettings

    Click Finish to create a data source. This creates the data source and displays its fields in the Data Source Browser.

Creating a Data Source in Code

The DashboardExcelDataSource class allows you to extract data from Microsoft Excel workbooks (XLS, XLSX or XLSM) or CSV files stored on the disk or stream.

To extract data from the specified workbook or CSV file, do the following.

Finally, add the created DashboardExcelDataSource object to the Dashboard.DataSources collection.

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);