[]
        
(Showing Draft Content)

IPivotItems

Interface IPivotItems

All Superinterfaces:
Iterable<IPivotItem>

public interface IPivotItems extends Iterable<IPivotItem>
Represents a collection of all IPivotItem objects in a PivotTable field.

Each item in the collection corresponds to an individual data entry in the field category. Use this interface to access pivot items returned by IPivotField.getPivotItems(), and then retrieve a specific item by index or name.


 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()
      Gets the number of IPivotItem objects in the collection.

      When this collection is returned by IPivotField.getPivotItems(), the count includes the items in that PivotTable field.

      
       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:
      The number of IPivotItem objects in the collection.
    • get

      IPivotItem get(int index)
      Returns the IPivotItem at the specified index in the collection.

      Use this method to retrieve a pivot item from the IPivotItems collection associated with a pivot field.

      
       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 - The zero-based index of the pivot item to return.
      Returns:
      The IPivotItem at the specified index.
    • get

      IPivotItem get(String name)
      Returns the IPivotItem with the specified name from the collection.

      Use this method to retrieve a pivot item from the IPivotItems collection associated with a pivot field.

      
       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 - The name of the pivot item to return.
      Returns:
      The IPivotItem with the specified name.