[]
        
(Showing Draft Content)

IPivotFields

Interface IPivotFields

All Superinterfaces:
Iterable<IPivotField>

public interface IPivotFields extends Iterable<IPivotField>
Represents the collection of IPivotField objects in a PivotTable report.

An IPivotFields collection contains all fields that belong to a PivotTable report, including fields that are not currently visible in the layout. Use this interface to enumerate fields or retrieve a field by index or by name.


 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()
      Gets the number of pivot fields in this collection.

      This method returns the total number of IPivotField objects available in the PivotTable field collection.

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

      IPivotField get(int index)
      Gets the pivot field at the specified index.

      Use this method to retrieve a single IPivotField from the IPivotFields collection by position.

      
       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 - The zero-based index of the pivot field to retrieve from the collection.
      Returns:
      The IPivotField at the specified index.
      Throws:
      IndexOutOfBoundsException - if index is outside the valid range of the collection.
    • get

      IPivotField get(String name)
      Gets the IPivotField with the specified name from this collection.

      Use this method to retrieve a PivotTable field by its display name in the current IPivotFields collection.

      
       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 - The name of the PivotTable field to retrieve. This value must match the field name in the collection.
      Returns:
      The IPivotField with the specified name.
      Throws:
      IllegalArgumentException - if no field with the specified name exists in the collection.