Back to Devexpress

ASPxPivotGridExporter.CustomExportCell Event

aspnet-devexpress-dot-web-dot-aspxpivotgrid-dot-aspxpivotgridexporter-13a93cd0.md

latest11.1 KB
Original Source

ASPxPivotGridExporter.CustomExportCell Event

Enables you to render a different content for individual cells, if the PivotGrid is exported in the WYSIWYG mode.

Namespace : DevExpress.Web.ASPxPivotGrid

Assembly : DevExpress.Web.ASPxPivotGrid.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event EventHandler<WebCustomExportCellEventArgs> CustomExportCell
vb
Public Event CustomExportCell As EventHandler(Of WebCustomExportCellEventArgs)

Event Data

The CustomExportCell event's data class is WebCustomExportCellEventArgs. The following properties provide information specific to this event:

PropertyDescription
AppearanceGets or sets the appearance settings used to paint the cell currently being exported.
ApplyAppearanceToBrickStyleSpecifies whether to apply the appearance settings to a brick. Inherited from CustomPrintEventArgs.
BrickProvides access to the brick that represents the contents and appearance of a cell, when it is printed or exported. Inherited from CustomPrintEventArgs.
ColumnFieldGets the column field that corresponds to the current cell.
ColumnFieldIndexFor internal use. Inherited from CustomExportCellEventArgsBase.
ColumnIndexGets the visual index of the column that contains the current cell. Inherited from CustomExportCellEventArgsBase.
ColumnValueGets information about a column field value that corresponds to the current cell. Inherited from CustomExportCellEventArgsBase.
DataFieldGets the data field that identifies the column/row where the processed cell resides.
FormatTypeGets the type of formatting. Inherited from CustomExportCellEventArgsBase.
IsTextFitGets whether the processed cell text is entirely displayed. Inherited from CustomExportCellEventArgsBase.
RectDefines the size and location of the printed or exported cell. Inherited from CustomPrintEventArgs.
RowFieldGets the row field that corresponds to the current cell.
RowFieldIndexFor internal use. Inherited from CustomExportCellEventArgsBase.
RowIndexGets the visual index of the row that contains the current cell. Inherited from CustomExportCellEventArgsBase.
RowValueGets information about a row field value that corresponds to the current cell. Inherited from CustomExportCellEventArgsBase.
TextGets the text displayed within the processed cell. Inherited from CustomExportCellEventArgsBase.
ValueGets the processed cell value. Inherited from CustomExportCellEventArgsBase.

The event data class exposes the following methods:

MethodDescription
CreateDrillDownDataSource()Returns data records used to calculate a summary value for the current cell. Inherited from CustomExportCellEventArgsBase.
CreateDrillDownDataSource(List<String>)Returns data records used to calculate a summary value for the current cell. Allows you to specify data columns for the returned records. Inherited from CustomExportCellEventArgsBase.
CreateDrillDownDataSource(Int32, List<String>)Returns data records used to calculate a summary value for the current cell. Allows you to specify the data columns and limit the number of returned records. Inherited from CustomExportCellEventArgsBase.
CreateDrillDownDataSource(Int32)Returns data records used to calculate a summary value for the current cell. Allows you to limit the number of returned records. Inherited from CustomExportCellEventArgsBase.

Remarks

The CustomExportCell event is raised for each cell when the ASPxPivotGrid is exported. You can handle this event to change the cell’s appearance and contents in a printed document.

Note

Data field properties cannot be changed in the CustomExportCell event handler.

Note

The CustomExportCell and ASPxPivotGridExporter.CustomExportFieldValue events are not in effect during the export in Data-Aware mode. To customize cells in Data-Aware export mode, use the PivotXlsExportOptions.CustomizeCell and PivotXlsxExportOptions.CustomizeCell events.

Example

This example shows how to display custom text within cells when the pivot grid’s data is exported to a file in XLS format. To do this, the ASPxPivotGridExporter.CustomExportCell event is handled.

The image below shows the result:

csharp
using System;
using System.Drawing;
using DevExpress.XtraPivotGrid.Web;
using DevExpress.XtraPrinting;

public partial class _Default : System.Web.UI.Page 
{
    static double maxPrice = 99;
    protected void ASPxPivotGridExporter1_CustomExportCell(
                          object sender,
                          WebCustomExportCellEventArgs e) {
        if (e.DataField.FieldName == "UnitPrice" &&
                Convert.ToDouble(e.Value) > 0 &&
                Convert.ToDouble(e.Value) < maxPrice) {
            // Specifies the cell's display text.
            ((TextBrick)e.Brick).Text = string.Format(
                     "Custom text: {0}",
                     ((TextBrick)e.Brick).Text);
            // Specifies the appearance settings used to paint the cell in a document.
            e.Appearance.BackColor = Color.Green;
            e.Appearance.ForeColor = Color.White;
        }
    }
    protected void ASPxButton1_Click(object sender, EventArgs e) {
        ASPxPivotGridExporter1.ExportToXls(@"C:\pivotdata.xls", TextExportMode.Text);
    }
}
aspx
<dx:ASPxButton ID="ASPxButton1" runat="server" OnClick="ASPxButton1_Click" Text="Export">
</dx:ASPxButton>

<dx:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server" ClientIDMode="AutoID" DataSourceID="SqlDataSource1">
    <Fields>
        <dx:PivotGridField ID="fieldProductName" Area="RowArea" AreaIndex="0" FieldName="ProductName">
        </dx:PivotGridField>
        <dx:PivotGridField ID="fieldCountry" Area="ColumnArea" AreaIndex="0" FieldName="Country">
        </dx:PivotGridField>
        <dx:PivotGridField ID="fieldQuantity" Area="DataArea" AreaIndex="1" FieldName="Quantity">
        </dx:PivotGridField>
        <dx:PivotGridField ID="fieldUnitPrice" Area="DataArea" AreaIndex="0" FieldName="UnitPrice">
        </dx:PivotGridField>
    </Fields>
</dx:ASPxPivotGrid>

<dx:ASPxPivotGridExporter ID="ASPxPivotGridExporter1" runat="server" 
   ASPxPivotGridID="ASPxPivotGrid1" OnCustomExportCell="ASPxPivotGridExporter1_CustomExportCell">
</dx:ASPxPivotGridExporter>

See Also

CustomExportFieldValue

CustomExportHeader

Pivot Grid Export

ASPxPivotGridExporter Class

ASPxPivotGridExporter Members

DevExpress.Web.ASPxPivotGrid Namespace