[]
Creates a new calculated item. Returns a IPivotItem object.
Use the returned item to access the calculated item after it is added to the pivot field's calculated items collection obtained from CalculatedItems().
IPivotItem Add(string name, string formula)
Function Add(name As String, formula As String) As IPivotItem
| Type | Name | Description |
|---|---|---|
| string | name | The name of the calculated item. |
| string | formula | The formula used to define the calculated item. |
| Type | Description |
|---|---|
| IPivotItem | The created IPivotItem. |
worksheet.Range["A1:B4"].Value = new object[,] {
{"Country", "Amount"},
{"France", 100},
{"Germany", 200},
{"Canada", 150}
};
IPivotCache pivotCache = workbook.PivotCaches.Create(worksheet.Range["A1:B4"]);
IPivotTable pivotTable = worksheet.PivotTables.Add(pivotCache, worksheet.Range["D1"], "PivotTable1");
pivotTable.PivotFields["Country"].Orientation = PivotFieldOrientation.RowField;
IPivotItem item = pivotTable.PivotFields["Country"].CalculatedItems().Add("Europe", "=France+Germany");