[]
        
(Showing Draft Content)

IPivotTables

Interface IPivotTables

All Superinterfaces:
Iterable<IPivotTable>

public interface IPivotTables extends Iterable<IPivotTable>
Represents the collection of all IPivotTable objects on a specified worksheet.

Use this interface to access existing PivotTable reports on a worksheet or to add new ones through add(IPivotCache,IRange) or add(IPivotCache,IRange,String). An IPivotTables instance is typically obtained from IWorksheet.getPivotTables().


 worksheet.getRange("A1:B3").setValue(new Object[][] {
     {"Name", "Value"},
     {"A", 100},
     {"B", 200}
 });
 IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
 worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
 IPivotTables pivotTables = worksheet.getPivotTables();
 
  • Method Details

    • getCount

      int getCount()
      Gets the number of IPivotTable objects in this collection.

      Use this method to determine how many PivotTable reports are available on the worksheet.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
       worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
       int count = worksheet.getPivotTables().getCount();
       
      Returns:
      The number of IPivotTable objects in this collection.
    • add

      IPivotTable add(IPivotCache PivotCache, IRange TableDestination)
      Adds a new PivotTable report.

      This overload forwards null as the table name to add(IPivotCache,IRange,String).

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Region", "Sales"},
           {"East", 120},
           {"West", 150},
           {"North", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"));
       
      Parameters:
      PivotCache - The PivotTable cache that provides the source data for the new PivotTable report.
      TableDestination - The upper-left cell of the destination range where the PivotTable report is placed. The destination range must be on the worksheet that contains this IPivotTables collection.
      Returns:
      The added IPivotTable.
    • add

      IPivotTable add(IPivotCache PivotCache, IRange TableDestination, String TableName)
      Adds a new PivotTable report.

      Creates a PivotTable report from the specified IPivotCache and places it at the specified destination range on the worksheet that contains this IPivotTables 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");
       
      Parameters:
      PivotCache - The PivotTable cache on which the new PivotTable report is based. This parameter must not be null.
      TableDestination - The upper-left cell of the destination range where the PivotTable report is placed. The destination range must be on the worksheet that contains this IPivotTables collection and must not be null.
      TableName - The name of the new PivotTable report. This value can be null.
      Returns:
      The added IPivotTable.
    • get

      IPivotTable get(int index)
      Gets the IPivotTable at the specified index from the collection.

      Use this method to retrieve an existing PivotTable report on the current worksheet by its position in the IPivotTables collection.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Region", "Sales"},
           {"East", 100},
           {"West", 200}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
       worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotTable pivotTable = worksheet.getPivotTables().get(0);
       
      Parameters:
      index - The zero-based index of the PivotTable to retrieve.
      Returns:
      The IPivotTable at the specified index in the collection.
    • get

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

      Use this method to retrieve an existing PivotTable report on the current worksheet by its name.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Region", "Sales"},
           {"East", 100},
           {"West", 200}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
       worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotTable pivotTable = worksheet.getPivotTables().get("SalesPivot");
       
      Parameters:
      name - The name of the PivotTable to retrieve.
      Returns:
      The IPivotTable with the specified name in the collection.