[]
        
(Showing Draft Content)

IPivotFormula

Interface IPivotFormula


public interface IPivotFormula
Represents a custom formula in a PivotTable report.

An IPivotFormula describes a formula defined in a PivotTable report, such as a formula created by a calculated item, and exposes its name, formula text, and calculation order within the PivotTable report.


 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", "=Apple + Banana");
 IPivotFormula pivotFormula = pivotTable.getPivotFormulas().get(0);
 
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the formula text of the current PivotTable custom formula.
    int
    Gets the solved order of the current PivotTable formula.
    Gets the name of the current PivotTable formula.
    void
    setIndex(int value)
    Sets the solved order of the current PivotTable formula.
  • Method Details

    • getFormula

      String getFormula()
      Gets the formula text of the current PivotTable custom formula.
      
       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", "=Apple + Banana");
       String formulaText = pivotTable.getPivotFormulas().get(0).getFormula();
       
      Returns:
      The formula text of the current PivotTable custom formula.
    • getIndex

      int getIndex()
      Gets the solved order of the current PivotTable formula.

      This value indicates the order in which the current custom formula is calculated relative to other formulas in the same PivotTable. Use setIndex(int) to change the calculation order, or IPivotTable.getPivotFormulas() to access the formula collection.

      
       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", "=Apple + Banana");
       int index = pivotTable.getPivotFormulas().get(0).getIndex();
       
      Returns:
      The solved order of the current formula.
    • setIndex

      void setIndex(int value)
      Sets the solved order of the current PivotTable formula.
      
       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", "=Apple + Banana");
       pivotTable.getPivotFormulas().get(0).setIndex(0);
       
      Parameters:
      value - The solved order of the current formula.
    • getName

      String getName()
      Gets the name of the current PivotTable formula.

      Use this method to retrieve the formula name from an IPivotFormula in the IPivotTable.getPivotFormulas() collection.

      
       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", "=Apple + Banana");
       String formulaName = pivotTable.getPivotFormulas().get(0).getName();
       
      Returns:
      The name of the current PivotTable formula.