Skip to main content

XlsxExportOptionsEx.CustomizeCell Event

Allows you to customize a cell in the output document. Only available in data-aware export mode.

Namespace: DevExpress.XtraPrinting

Assembly: DevExpress.Printing.v24.1.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

public event CustomizeCellEventHandler CustomizeCell

Remarks

To learn about the functionality provided by this event, see XlsExportOptionsEx.CustomizeCell.

Example

This example uses the XlsxExportOptionsEx.CustomizeCell event to replace values in the Discontinued column in an XLSX document (a result of data exporting from a Grid Control) with special symbols. The ColumnName event parameter allows recognizing the desired column. The Value parameter is utilized to substitute certain cell values. The Handled parameter is set to true to apply the changes made.

GridExportOutputResult

// Specify the value alignment for Discontinued field.
XlCellAlignment aligmentForDiscontinuedColumn = new XlCellAlignment() {
    HorizontalAlignment = XlHorizontalAlignment.Center,
    VerticalAlignment = XlVerticalAlignment.Center
};

void options_CustomizeCell(CustomizeCellEventArgs e){
    // Substitute Boolean values within the Discontinued column by special symbols.
    if(e.ColumnFieldName == "Discontinued"){
        if(e.Value is bool){
            e.Handled = true;
            e.Formatting.Alignment = aligmentForDiscontinuedColumn;
            e.Value = ((bool) e.Value) ? "☑" : "☐";
        }
    }
}

Example

The following example exports data from a GridControl to XLS format. The XlsExportOptionsEx.CustomizeCell event is used to change the background of the grid control’s City column in the output document, and to provide hyperlinks for this column’s cells. Note that the Handled event parameter is set to true to apply the changes made.

Grid-XlsExportOptionsEx.CustomizeCell

using DevExpress.XtraPrinting;

// Ensure that the data-aware export mode is enabled.
DevExpress.Export.ExportSettings.DefaultExportType = DevExpress.Export.ExportType.DataAware;

private void button1_Click(object sender, EventArgs e) {
    string file = "c:\\work\\grid-export.xls";
    XlsExportOptionsEx op = new XlsExportOptionsEx();
    op.CustomizeCell += op_CustomizeCell;
    gridView1.ExportToXls(file, op);
    System.Diagnostics.Process.Start(file);
}

void op_CustomizeCell(DevExpress.Export.CustomizeCellEventArgs ea) {
    if (ea.ColumnFieldName == "City") {
        ea.Hyperlink = "https://www.google.com/search?q=" + ea.Value.ToString();
        ea.Formatting.BackColor = Color.Pink;
        ea.Handled = true;
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the CustomizeCell event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also