[]
        
首页
开发者学堂
文档
论坛
市场
生态机会
活动
立即试用
(Showing Draft Content)

IPivotFormulas

Interface IPivotFormulas

All Superinterfaces:
Iterable<IPivotFormula>

public interface IPivotFormulas extends Iterable<IPivotFormula>
表示 PivotTable 中自定义公式的集合。

IPivotFormulas 对象由 IPivotTable.getPivotFormulas() 返回,并提供对为 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]");
 IPivotFormulas formulas = pivotTable.getPivotFormulas();
 
  • Method Details

    • getCount

      int getCount()
      获取此集合中的数据透视公式数量。

      此集合由 IPivotTable.getPivotFormulas() 返回,包含为 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]");
       int count = pivotTable.getPivotFormulas().getCount();
       
      Returns:
      集合中的数据透视公式数量。
    • get

      IPivotFormula get(int index)
      获取指定索引处的 IPivotFormula。

      使用此方法可从 IPivotTable.getPivotFormulas() 集合中检索公式,例如由 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 - 要检索的透视公式的索引。
      Returns:
      指定索引处的 IPivotFormula。