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

IPivotTables

Interface IPivotTables

All Superinterfaces:
Iterable<IPivotTable>

public interface IPivotTables extends Iterable<IPivotTable>
表示指定工作表上所有 IPivotTable 对象的集合。

使用此接口可以访问工作表上的现有数据透视表报表,或通过 add(IPivotCache,IRange) 或 add(IPivotCache,IRange,String) 添加新的数据透视表报表。IPivotTables 实例通常从 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()
      获取此集合中 IPivotTable 对象的数量。

      使用此方法可以确定工作表上可用的数据透视表报告数量。

      
       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:
      此集合中 IPivotTable 对象的数量。
    • add

      IPivotTable add(IPivotCache PivotCache, IRange TableDestination)
      添加新的数据透视表报告。

      此重载会将 null 作为表名称传递给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 - 为新数据透视表报告提供源数据的数据透视表缓存。
      TableDestination - 放置数据透视表报告的目标区域左上角单元格。目标区域必须位于包含此 IPivotTables 集合的工作表上。
      Returns:
      添加的 IPivotTable 对象。
    • add

      IPivotTable add(IPivotCache PivotCache, IRange TableDestination, String TableName)
      添加新的数据透视表报告。

      从指定的 IPivotCache 创建数据透视表报告,并将其放置在包含此 IPivotTables 集合的工作表上的指定目标区域。

      
       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 - 新数据透视表报告所基于的数据透视表缓存。此参数不得为 null。
      TableDestination - 放置数据透视表报告的目标区域左上角单元格。目标区域必须位于包含此 IPivotTables 集合的工作表上,并且不得为 null。
      TableName - 新数据透视表报告的名称。此值可以为 null。
      Returns:
      添加的 IPivotTable 对象。
    • get

      IPivotTable get(int index)
      从集合中获取指定索引处的 IPivotTable。

      使用此方法可以按 IPivotTables 集合中的位置检索当前工作表上的现有数据透视表报告。

      
       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 - 要检索的 PivotTable 的从零开始的索引。
      Returns:
      集合中指定索引处的 IPivotTable 对象。
    • get

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

      使用此方法可以按名称检索当前工作表上的现有数据透视表报告。

      
       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 - 要检索的 PivotTable 的名称。
      Returns:
      集合中具有指定名称的 IPivotTable 对象。