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

IPivotFields

Interface IPivotFields

All Superinterfaces:
Iterable<IPivotField>

public interface IPivotFields extends Iterable<IPivotField>
表示数据透视表报表中的 IPivotField 对象集合。

IPivotFields 集合包含属于数据透视表报表的所有字段,包括当前在布局中不可见的字段。使用此接口可以枚举字段,或按索引或名称检索字段。


 worksheet.getRange("A1:C4").setValue(new Object[][] {
     {"Product", "Region", "Amount"},
     {"Apple", "East", 100},
     {"Pear", "West", 200},
     {"Apple", "West", 150}
 });
 IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
 IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
 IPivotFields pivotFields = pivotTable.getPivotFields();
 IPivotField amountField = pivotFields.get("Amount");
 
  • Method Details

    • getCount

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

      此方法返回 PivotTable 字段集合中可用的 IPivotField 对象总数。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 120},
           {"West", "Orange", 80},
           {"East", "Orange", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       int count = pivotTable.getPivotFields().getCount();
       
      Returns:
      集合中数据透视字段的数量。
    • get

      IPivotField get(int index)
      获取指定索引处的数据透视字段。

      使用此方法可按位置从 IPivotFields 集合中检索单个 IPivotField。

      
       worksheet.getRange("A1:B5").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Fruit", 120},
           {"Fruit", 80},
           {"Vegetables", 95},
           {"Vegetables", 60}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get(0);
       field.setOrientation(PivotFieldOrientation.RowField);
       
      Parameters:
      index - 要从集合中检索的数据透视字段 的索引。
      Returns:
      指定索引处的 IPivotField。
      Throws:
      IndexOutOfBoundsException - 如果 index 超出集合的有效范围。
    • get

      IPivotField get(String name)
      从此集合中获取具有指定名称的 IPivotField。

      使用此方法可通过当前 IPivotFields 集合中的显示名称检索 PivotTable 字段。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 120},
           {"West", "Apple", 80},
           {"East", "Orange", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Product");
       
      Parameters:
      name - 要检索的 PivotTable 字段名称。此值必须与集合中的字段名称匹配。
      Returns:
      具有指定名称的 IPivotField。
      Throws:
      IllegalArgumentException - 如果集合中不存在具有指定名称的字段。