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

IPivotItems

Interface IPivotItems

All Superinterfaces:
Iterable<IPivotItem>

public interface IPivotItems extends Iterable<IPivotItem>
表示数据透视字段中所有 IPivotItem 对象的集合。

集合中的每一项对应字段类别中的单个数据条目。使用此接口可以访问由 IPivotField.getPivotItems() 返回的数据透视项,然后按索引或名称检索特定项。


 Object[][] sourceData = {
     {"Region", "Amount"},
     {"North", 100},
     {"South", 200},
     {"East", 150}
 };
 worksheet.getRange("A1:B4").setValue(sourceData);
 IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
 IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "salesPivot");
 IPivotField field = pivotTable.getPivotFields().get("Region");
 field.setOrientation(PivotFieldOrientation.RowField);
 IPivotItems items = field.getPivotItems();
 items.get("North").setVisible(false);
 
  • Method Details

    • getCount

      int getCount()
      获取集合中 IPivotItem 对象的数量。

      当此集合由 IPivotField.getPivotItems() 返回时,计数包括该 PivotTable 字段中的项。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Region", "Amount"},
           {"East", 100},
           {"West", 200},
           {"East", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Region");
       field.setOrientation(PivotFieldOrientation.RowField);
       int count = field.getPivotItems().getCount();
       
      Returns:
      集合中 IPivotItem 对象的数量。
    • get

      IPivotItem get(int index)
      返回集合中指定索引处的 IPivotItem。

      使用此方法可获取与数据透视字段关联的 IPivotItems 集合中的数据透视项。

      
       Object[][] sourceData = {
           {"Category", "Product", "Amount"},
           {"Beverages", "Tea", 10},
           {"Beverages", "Coffee", 20},
           {"Snacks", "Cookie", 15}
       };
       worksheet.getRange("A1:C4").setValue(sourceData);
       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");
       field.setOrientation(PivotFieldOrientation.RowField);
       IPivotItem item = field.getPivotItems().get(0);
       String name = item.getName();
       
      Parameters:
      index - 要返回的数据透视项的索引号。
      Returns:
      指定索引处的 IPivotItem。
    • get

      IPivotItem get(String name)
      返回集合中具有指定名称的 IPivotItem。

      使用此方法可获取与数据透视字段关联的 IPivotItems 集合中的数据透视项。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Banana", 80},
           {"Apple", 120}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Product");
       field.setOrientation(PivotFieldOrientation.RowField);
       IPivotItem item = field.getPivotItems().get("Apple");
       
      Parameters:
      name - 要返回的数据透视项的名称。
      Returns:
      具有指定名称的 IPivotItem。