Skip to main content
All docs
V24.2

CustomizeExportDocumentWebEventArgs.GetDashboardItem(String) Method

Returns a dashboard item that corresponds the specified component name.

Namespace: DevExpress.DashboardWeb

Assembly: DevExpress.Dashboard.v24.2.Web.dll

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 code snippet below demonstrates how to 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.

using DevExpress.DashboardAspNetCore;
using DevExpress.DashboardCommon;
using DevExpress.DashboardCommon.ViewerData;
using DevExpress.DashboardWeb;
using DevExpress.Spreadsheet;
using System.Collections.Generic;
using System.Drawing;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDevExpressControls();
builder.Services.AddScoped<DashboardConfigurator>((IServiceProvider serviceProvider) => {
    DashboardConfigurator configurator = new DashboardConfigurator();
    // ...
    configurator.CustomizeExportDocument += Configurator_CustomizeExportDocument;

    return configurator;
});

var app = builder.Build();
// ...
app.Run();

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

The following image demonstrates the resulting document:

Funnel custom export to Excel

See Also