[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.IPivotItem.Formula

Formula Property

Formula

Gets or sets the formula of the calculated item.

Use this property to retrieve the formula text defined for a calculated item in a PivotTable field.

Declaration
string Formula { get; set; }
Property Formula As String
Examples
worksheet.Range["A1:C4"].Value = new object[,] {
    {"Product", "Category", "Amount"},
    {"Apple", "Fruit", 10},
    {"Banana", "Fruit", 20},
    {"Carrot", "Vegetable", 15}
};
IPivotCache pivotCache = workbook.PivotCaches.Create(worksheet.Range["A1:C4"]);
IPivotTable pivotTable = pivotCache.CreatePivotTable(worksheet.Range["E1"], "PivotTable1");
pivotTable.PivotFields["Product"].Orientation = PivotFieldOrientation.RowField;
pivotTable.PivotFields["Category"].Orientation = PivotFieldOrientation.ColumnField;
pivotTable.PivotFields["Amount"].Orientation = PivotFieldOrientation.DataField;
IPivotItem item = pivotTable.PivotFields["Product"].CalculatedItems().Add("TotalFruit", "=Apple + Banana");
string formula = item.Formula;