[]
        
(Showing Draft Content)

IPivotFormulas

Interface IPivotFormulas

All Superinterfaces:
Iterable<IPivotFormula>

public interface IPivotFormulas extends Iterable<IPivotFormula>
Represents the collection of custom formulas in a PivotTable.

An IPivotFormulas object is returned by IPivotTable.getPivotFormulas() and provides access to the formulas defined for a PivotTable, such as formulas created by calculated items.


 worksheet.getRange("A1:C4").setValue(new Object[][] {
     {"Product", "Category", "Amount"},
     {"Apple", "Fruit", 120},
     {"Banana", "Fruit", 80},
     {"Bran", "Snack", 60}
 });
 IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
 IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
 pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
 pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
 pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
 pivotTable.getPivotFields().get("Product").getCalculatedItems().add("TotalFruit", "=Product[Apple] + Product[Banana]");
 IPivotFormulas formulas = pivotTable.getPivotFormulas();
 
  • Method Details

    • getCount

      int getCount()
      Gets the number of pivot formulas in this collection.

      This collection is returned by IPivotTable.getPivotFormulas() and contains the formulas defined for a PivotTable, such as formulas created by calculated items.

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Product", "Category", "Amount"},
           {"Apple", "Fruit", 120},
           {"Banana", "Fruit", 80},
           {"Bran", "Snack", 60}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Product").getCalculatedItems().add("TotalFruit", "=Product[Apple] + Product[Banana]");
       int count = pivotTable.getPivotFormulas().getCount();
       
      Returns:
      The number of pivot formulas in the collection.
    • get

      IPivotFormula get(int index)
      Gets the IPivotFormula at the specified index.

      Use this method to retrieve a formula from the IPivotTable.getPivotFormulas() collection, such as a formula created by a calculated item in a PivotTable.

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Product", "Category", "Amount"},
           {"Apple", "Fruit", 120},
           {"Banana", "Fruit", 80},
           {"Bran", "Snack", 60}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Product").getCalculatedItems().add("TotalFruit", "=Product[Apple] + Product[Banana]");
       IPivotFormula formula = pivotTable.getPivotFormulas().get(0);
       
      Parameters:
      index - The index of the pivot formula to retrieve.
      Returns:
      The IPivotFormula at the specified index.