Skip to main content
A newer version of this page is available. .
All docs
V23.1

CustomizeExportDocumentWebEventArgs.GetDashboardItem(String) Method

Returns a dashboard item that corresponds the specified component name.

Namespace: DevExpress.DashboardWeb

Assembly: DevExpress.Dashboard.v23.1.Web.dll

NuGet Package: DevExpress.Web.Dashboard.Common

Declaration

public DashboardItem GetDashboardItem(
    string dashboardItemName
)

Parameters

Name Type Description
dashboardItemName String

A string that is the dashboard item’s component name.

Returns

Type Description
DashboardItem

A dashboard item that corresponds the specified component name.

Remarks

The code snippet below demonstrates how you can generate an XLSX document. The code uses Spreadsheet Document API to modify the generated document’s layout and content. This library is part of the DevExpress Office File API suite. The e.GetDashboardItem method gets the custom Funnel Chart item by its component name.

using DevExpress.DashboardAspNetCore;
using DevExpress.DashboardCommon;
using DevExpress.DashboardCommon.ViewerData;
using DevExpress.DashboardWeb;
using DevExpress.Spreadsheet;
using System.Collections.Generic;
using System.Drawing;
// ...
public void ConfigureServices(IServiceCollection services) {
    //...
    services.AddScoped<DashboardConfigurator>((IServiceProvider serviceProvider) => {
        DashboardConfigurator configurator = new DashboardConfigurator();
        // ...
        configurator.CustomizeExportDocument += Configurator_CustomizeExportDocument;

        return configurator;
    });

private void Configurator_CustomizeExportDocument(object sender, CustomizeExportDocumentWebEventArgs e) {
    if (e.ExportAction == DashboardExportAction.ExportToExcel && e.ExcelExportOptions.Format == ExcelFormat.Xlsx) {
        CustomDashboardItem item = e.GetDashboardItem("customItemDashboardItem2") as CustomDashboardItem;

        if (item != null) {
            DevExpress.Spreadsheet.Workbook workbook = new DevExpress.Spreadsheet.Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            MultiDimensionalData itemData = e.GetItemData(e.ItemComponentName);
            CustomItemData customItemData = new CustomItemData(item, itemData);

            DashboardFlatDataSource flatData = customItemData.GetFlatData();
            IList<DashboardFlatDataColumn> columns = flatData.GetColumns();
            for (int colIndex = 0; colIndex < columns.Count; colIndex++) {
                worksheet.Cells[0, colIndex].Value = columns[colIndex].DisplayName;
                worksheet.Cells[0, colIndex].FillColor = Color.LightGreen;
                worksheet.Cells[0, colIndex].Font.FontStyle = SpreadsheetFontStyle.Bold;
                int headerOffset = 1;
                for (int rowIndex = 0; rowIndex < flatData.Count; rowIndex++)
                    worksheet.Cells[rowIndex + headerOffset, colIndex].Value = flatData.GetDisplayText(columns[colIndex].Name, rowIndex);

            }
            e.Stream.SetLength(0);
            workbook.SaveDocument(e.Stream, DocumentFormat.Xlsx);
        }
    }
}
See Also