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

IPivotItem

Interface IPivotItem


public interface IPivotItem
表示数据透视字段中的数据透视项。

IPivotItem 对应于 IPivotField 中的单个项值。使用此接口可处理该项的名称、源名称、位置、可见性、展开状态以及计算项公式。可从数据透视字段的 IPivotItems 集合获取数据透视项。


 worksheet.getRange("A1:B4").setValue(new Object[][] {
     {"Category", "Amount"},
     {"Beverages", 100},
     {"Snacks", 200},
     {"Beverages", 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("Category");
 field.setOrientation(PivotFieldOrientation.RowField);
 IPivotItem item = field.getPivotItems().get(0);
 item.setVisible(false);
 
  • Method Summary

    Modifier and Type
    Method
    Description
    获取 PivotItem 的显示标题重写值。
    获取计算项的公式。
    获取 pivot item 的名称。
    int
    获取数据透视项在其父字段中的位置(当该项当前显示时)。
    boolean
    获取数据透视项是否已展开,以便其详细行或列可见。
    获取此 PivotTable 项在原始源数据中显示的名称。
    boolean
    获取数据透视项是否可见。
    void
    设置 PivotItem 的显示标题重写值。
    void
    设置计算项的公式。
    void
    setName(String value)
    设置 pivot 项的名称。
    void
    setPosition(int value)
    设置项在其父字段中的数据透视项位置(当该项当前显示时)。
    void
    setShowDetail(boolean value)
    设置数据透视项是否展开,以便其明细行或列可见。
    void
    setVisible(boolean value)
    设置数据透视项是否可见。
  • Method Details

    • getCaption

      String getCaption()
      获取 PivotItem 的显示标题重写值。

      标题是在 PivotTable 布局中显示的文本。当项具有自定义标签时,它可以不同于 getName() 和 getSourceName()。

      
       Workbook workbook = new Workbook();
       IWorksheet worksheet = workbook.getWorksheets().get(0);
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Product", "Region", "Amount"},
           {"Apple", "East", 10},
           {"Banana", "West", 20},
           {"Carrot", "East", 30},
           {"Date", "West", 40}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotItem item = pivotTable.getPivotFields().get("Product").getPivotItems().get("Apple");
       item.setCaption("Fresh Apple");
       String caption = item.getCaption();
       
      Returns:
      PivotItem 的显示标题重写值。如果未设置自定义标题,则返回 null。
    • setCaption

      void setCaption(String value)
      设置 PivotItem 的显示标题重写值。

      null 值会清除标题重写值。

      
       Workbook workbook = new Workbook();
       IWorksheet worksheet = workbook.getWorksheets().get(0);
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Product", "Region", "Amount"},
           {"Apple", "East", 10},
           {"Banana", "West", 20},
           {"Carrot", "East", 30},
           {"Date", "West", 40}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotItem item = pivotTable.getPivotFields().get("Product").getPivotItems().get("Apple");
       item.setCaption("Fresh Apple");
       String caption = item.getCaption();
       
      Parameters:
      value - PivotItem 的显示标题重写值。使用 null 可清除标题重写值。
    • getName

      String getName()
      获取 pivot item 的名称。

      此方法返回该项在其父级 IPivotField 中的当前名称。如果在创建 PivotTable 后重命名了该项,则返回的值可能与 getSourceName() 不同。

      
       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);
       String name = field.getPivotItems().get("Apple").getName();
       
      Returns:
      pivot item 的当前名称。
    • setName

      void setName(String value)
      设置 pivot 项的名称。

      此方法设置该项在其父级 IPivotField 中的当前名称。如果在创建 PivotTable 之后该项被重命名,则返回的值可能与 getSourceName() 不同。

      
       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);
       field.getPivotItems().get(0).setName("Orange");
       
      Parameters:
      value - pivot 项的当前名称。
    • getPosition

      int getPosition()
      获取数据透视项在其父字段中的位置(当该项当前显示时)。

      该值表示该项在字段中的显示顺序。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Banana", 80},
           {"Carrot", 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);
       int position = field.getPivotItems().get("Apple").getPosition();
       
      Returns:
      当该项当前显示时,数据透视项在其字段中的位置。
    • setPosition

      void setPosition(int value)
      设置项在其父字段中的数据透视项位置(当该项当前显示时)。

      此值表示该项在字段中的显示顺序。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Banana", 80},
           {"Carrot", 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);
       field.getPivotItems().get("Apple").setPosition(0);
       
      Parameters:
      value - 该项当前显示时,数据透视项在其字段中的位置。
    • getShowDetail

      boolean getShowDetail()
      获取数据透视项是否已展开,以便其详细行或列可见。

      此属性返回数据透视项在其父 数据透视字段中的当前大纲状态。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"}, {"Fruit", 100}, {"Fruit", 200}, {"Drink", 50}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
       pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       pivotTable.update();
       boolean expanded = pivotTable.getPivotFields().get("Category").getPivotItems().get("Fruit").getShowDetail();
       
      Returns:
      如果数据透视项已展开,则为 true;否则为 false。
    • setShowDetail

      void setShowDetail(boolean value)
      设置数据透视项是否展开,以便其明细行或列可见。

      此属性设置该数据透视项在其父 数据透视字段中的当前大纲状态。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"}, {"Fruit", 100}, {"Fruit", 200}, {"Drink", 50}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
       pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       pivotTable.update();
       pivotTable.getPivotFields().get("Category").getPivotItems().get("Fruit").setShowDetail(true);
       
      Parameters:
      value - 如果数据透视项已展开,则为 true;否则为 false。
    • getSourceName

      String getSourceName()
      获取此 PivotTable 项在原始源数据中显示的名称。

      如果该项是在创建 PivotTable 后被重命名的,则此值可能与当前项名称不同。

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Coffee", 100},
           {"Tea", 200}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
       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("Coffee");
       String sourceName = item.getSourceName();
       
      Returns:
      原始源数据中的项名称。
    • getVisible

      boolean getVisible()
      获取数据透视项是否可见。

      此方法返回该项在其父 数据透视字段中的当前可见性状态。使用 setVisible(boolean) 可更改该项的可见性。

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Example Speaker", 100},
           {"Example Camera", 200}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
       IPivotField productField = pivotTable.getPivotFields().get("Product");
       productField.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       productField.getPivotItems().get("Example Speaker").setVisible(false);
       boolean visible = productField.getPivotItems().get("Example Speaker").getVisible();
       
      Returns:
      如果数据透视项可见,则为 true;否则为 false。
    • setVisible

      void setVisible(boolean value)
      设置数据透视项是否可见。
      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Example Speaker", 100},
           {"Example Camera", 200}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
       IPivotField productField = pivotTable.getPivotFields().get("Product");
       productField.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       productField.getPivotItems().get("Example Speaker").setVisible(false);
       
      Parameters:
      value - 如果数据透视项可见,则为 true;否则为 false。
    • getFormula

      String getFormula()
      获取计算项的公式。

      使用此方法可获取在 PivotTable 字段中为计算项定义的公式文本。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Product", "Category", "Amount"},
           {"Apple", "Fruit", 10},
           {"Banana", "Fruit", 20},
           {"Carrot", "Vegetable", 15}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = pivotCache.createPivotTable(worksheet.getRange("E1"), "PivotTable1");
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotItem item = pivotTable.getPivotFields().get("Product").getCalculatedItems().add("TotalFruit", "=Apple + Banana");
       String formula = item.getFormula();
       
      Returns:
      计算项的公式文本。
    • setFormula

      void setFormula(String value)
      设置计算项的公式。

      使用此方法可设置为 PivotTable 字段中的计算项定义的公式文本。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Product", "Category", "Amount"},
           {"Apple", "Fruit", 10},
           {"Banana", "Fruit", 20},
           {"Carrot", "Vegetable", 15}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = pivotCache.createPivotTable(worksheet.getRange("E1"), "PivotTable1");
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotItem item = pivotTable.getPivotFields().get("Product").getCalculatedItems().add("TotalFruit", "=Apple + Banana");
       item.setFormula("=Apple + Carrot");
       
      Parameters:
      value - 计算项的公式文本。