[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.IPivotTable.AddDataField

AddDataField Method

AddDataField(IPivotField, string, ConsolidationFunction)

Adds a data field to the PivotTable report.

Use this method to add a source field to the values area and specify the summary function used for that data field.

Declaration
IPivotField AddDataField(IPivotField field, string caption, ConsolidationFunction function)
Function AddDataField(field As IPivotField, caption As String, [function] As ConsolidationFunction) As IPivotField
Parameters
Type Name Description
IPivotField field

The unique field on the server. If the source data is OLAP, this field is a cube field; otherwise, it is a PivotTable field.

string caption

The label used in the PivotTable report to identify the added data field.

ConsolidationFunction function

The function performed in the added data field.

Returns
Type Description
IPivotField

The IPivotField added to the data area.

Examples
object[,] sourceData = {
    {"Region", "Product", "Amount"},
    {"East", "Apple", 120},
    {"West", "Apple", 80},
    {"East", "Orange", 90}
};
worksheet.Range["A1:C4"].Value = sourceData;
IPivotCache pivotCache = workbook.PivotCaches.Create(worksheet.Range["A1:C4"]);
IPivotTable pivotTable = worksheet.PivotTables.Add(pivotCache, worksheet.Range["E1"], "SalesPivot");
pivotTable.PivotFields["Region"].Orientation = PivotFieldOrientation.RowField;
pivotTable.AddDataField(pivotTable.PivotFields["Amount"], "Sum of Amount", ConsolidationFunction.Sum);