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

IPivotField

Interface IPivotField


public interface IPivotField
表示数据透视表报表中的一个字段。

IPivotField 是 IPivotFields 集合的一个成员,用于描述源字段在数据透视表报表中的使用方式,包括隐藏字段。使用此接口可以访问字段元数据、更改字段方向、配置排序和筛选,以及处理行、列、页或数据字段。


 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("Category");
 field.setOrientation(PivotFieldOrientation.RowField);
 
  • Method Details

    • getAllItemsVisible

      boolean getAllItemsVisible()
      获取 PivotField 中的所有项是否均可见。

      当通过隐藏一个或多个项应用了手动筛选时,返回 false。使用 clearManualFilter() 可恢复所有项的可见性。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Example Speaker", 4270},
           {"Example Camera", 8239},
           {"Example Appliance", 617}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
       IPivotField productField = pivotTable.getPivotFields().get("Product");
       productField.setOrientation(PivotFieldOrientation.RowField);
       productField.getPivotItems().get("Example Camera").setVisible(false);
       boolean allItemsVisible = productField.getAllItemsVisible();
       
      Returns:
      如果未应用手动筛选且字段中的所有项均可见,则为 true;否则为 false。
    • getAutoSortField

      String getAutoSortField()
      获取用于自动排序此 PivotTable 字段的数据字段名称。

      如果通过 autoSort(SortOrder,String) 配置了自动排序,则此方法返回为该规则指定的排序键字段名称。

      
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Product", "Region", "Amount"},
           {"Apple", "East", 120},
           {"Orange", "West", 80},
           {"Apple", "West", 150},
           {"Orange", "East", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       IPivotField regionField = pivotTable.getPivotFields().get("Region");
       regionField.setOrientation(PivotFieldOrientation.RowField);
       IPivotField amountField = pivotTable.getPivotFields().get("Amount");
       pivotTable.addDataField(amountField, "Sum of Amount", ConsolidationFunction.Sum);
       regionField.autoSort(SortOrder.Descending, amountField.getSourceName());
       String autoSortField = regionField.getAutoSortField();
       
      Returns:
      用于自动排序的数据字段名称。
    • getAutoSortOrder

      SortOrder getAutoSortOrder()
      获取此 PivotTable 字段的自动排序顺序。

      如果通过 autoSort(SortOrder) 或 autoSort(SortOrder,String) 配置了自动排序,则此方法返回应用于该字段的 SortOrder。

      
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Product", "Region", "Amount"},
           {"Apple", "East", 120},
           {"Orange", "West", 80},
           {"Apple", "West", 150},
           {"Orange", "East", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       IPivotField regionField = pivotTable.getPivotFields().get("Region");
       regionField.setOrientation(PivotFieldOrientation.RowField);
       regionField.autoSort(SortOrder.Descending);
       SortOrder autoSortOrder = regionField.getAutoSortOrder();
       
      Returns:
      PivotTable 字段的自动排序顺序。
    • getBaseField

      String getBaseField()
      获取用于自定义计算的基字段名称。

      此属性仅对数据字段有效。当数据字段配置为通过自定义计算(例如 PivotFieldCalculation.PercentOf)显示值时,可将此属性与 getCalculation() 一起使用。

      
       Object[][] sourceData = {
           {"Product", "Country", "Amount"},
           {"Bike", "Australia", 100},
           {"Bike", "Canada", 80}
       };
       worksheet.getRange("A1:C3").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"));
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Country").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotField dataField = pivotTable.getDataFields().get("Sum of Amount");
       dataField.setCalculation(PivotFieldCalculation.PercentOf);
       dataField.setBaseField("Country");
       String baseField = dataField.getBaseField();
       
      Returns:
      用于自定义计算的基字段名称。
    • setBaseField

      void setBaseField(String value)
      设置用于自定义计算的基础字段名称。

      此属性仅对数据字段有效。当数据字段配置为按自定义计算(例如 PivotFieldCalculation.PercentOf)显示值时,请将此属性与 getCalculation() 一起使用。

      
       Object[][] sourceData = {
           {"Product", "Country", "Amount"},
           {"Bike", "Australia", 100},
           {"Bike", "Canada", 80}
       };
       worksheet.getRange("A1:C3").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"));
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Country").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotField dataField = pivotTable.getDataFields().get("Sum of Amount");
       dataField.setCalculation(PivotFieldCalculation.PercentOf);
       dataField.setBaseField("Country");
       
      Parameters:
      value - 用于自定义计算的基础字段名称。
    • getBaseItem

      String getBaseItem()
      获取用于自定义计算的基字段中的项。

      此属性仅对数据字段有效。可将此属性与 getBaseField() 和 getCalculation() 一起使用,以确定自定义计算(例如 PivotFieldCalculation.PercentOf)所使用的基字段中的项。

      
       Object[][] sourceData = {
           {"Product", "Country", "Amount"},
           {"Bike", "Australia", 100},
           {"Bike", "Canada", 80}
       };
       worksheet.getRange("A1:C3").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"));
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Country").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotField dataField = pivotTable.getDataFields().get("Sum of Amount");
       dataField.setCalculation(PivotFieldCalculation.PercentOf);
       dataField.setBaseField("Country");
       dataField.setBaseItem("Australia");
       String baseItem = dataField.getBaseItem();
       
      Returns:
      用于自定义计算的基字段中的项名称。
    • setBaseItem

      void setBaseItem(String value)
      设置自定义计算中基础字段里的项目。

      此属性仅对数据字段有效。将此属性与 getBaseField() 和 getCalculation() 一起使用,以确定基础字段中哪个项目被用于 PivotFieldCalculation.PercentOf 等自定义计算。

      
       Object[][] sourceData = {
           {"Product", "Country", "Amount"},
           {"Bike", "Australia", 100},
           {"Bike", "Canada", 80}
       };
       worksheet.getRange("A1:C3").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"));
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Country").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotField dataField = pivotTable.getDataFields().get("Sum of Amount");
       dataField.setCalculation(PivotFieldCalculation.PercentOf);
       dataField.setBaseField("Country");
       dataField.setBaseItem("Australia");
       
      Parameters:
      value - 基础字段中用于自定义计算的项目名称。
    • getCalculation

      PivotFieldCalculation getCalculation()
      获取一个 PivotFieldCalculation 值,该值表示指定字段执行的计算类型。

      此属性仅对数据字段有效。

      
       Object[][] sourceData = {
           {"Product", "Country", "Amount"},
           {"Bike", "Australia", 100},
           {"Bike", "Canada", 80}
       };
       worksheet.getRange("A1:C3").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"));
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Country").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotField dataField = pivotTable.getDataFields().get("Sum of Amount");
       dataField.setCalculation(PivotFieldCalculation.PercentOf);
       PivotFieldCalculation calculation = dataField.getCalculation();
       
      Returns:
      一个 PivotFieldCalculation 值,指示该字段执行的计算类型。
    • setCalculation

      void setCalculation(PivotFieldCalculation value)
      设置 PivotFieldCalculation 值,该值指定在 PivotTable 中如何计算数据字段。

      此属性仅对数据字段有效。使用它可将数据字段从默认计算更改为自定义计算,例如 PivotFieldCalculation.PercentOf。

      
       Object[][] sourceData = {
           {"Product", "Country", "Amount"},
           {"Bike", "Australia", 100},
           {"Bike", "Canada", 80}
       };
       worksheet.getRange("A1:C3").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"));
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Country").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       IPivotField dataField = pivotTable.getDataFields().get("Sum of Amount");
       dataField.setCalculation(PivotFieldCalculation.PercentOf);
       
      Parameters:
      value - 指定数据字段计算类型的 PivotFieldCalculation 值。
    • getCurrentPage

      int getCurrentPage()
      获取页面字段当前显示的页面项索引。

      此方法仅对页面字段有效。返回的索引从零开始。值 -1 表示页面字段显示的是 All 或多个项目。

      
       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 pageField = pivotTable.getPivotFields().get("Region");
       pageField.setOrientation(PivotFieldOrientation.PageField);
       int currentPage = pageField.getCurrentPage();
       
      Returns:
      页面字段当前页面项的从零开始的索引;如果页面字段显示的是 All 或多个项目,则为 -1。
    • setCurrentPage

      void setCurrentPage(int value)
      设置页字段当前显示页项的索引。

      此方法仅对页字段有效。返回的索引从零开始。值 -1 表示页字段正在显示 All 或多个项。

      
       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 pageField = pivotTable.getPivotFields().get("Region");
       pageField.setOrientation(PivotFieldOrientation.PageField);
       pageField.setCurrentPage(0);
       
      Parameters:
      value - 页字段当前页项的从零开始的索引;如果页字段正在显示 All 或多个项,则为 -1。
    • getDragToColumn

      boolean getDragToColumn()
      获取指定字段是否可以拖动到列位置。

      此属性指示是否可以将该字段移动到数据透视表报表的列区域。默认值为 true。使用 setDragToColumn(boolean) 可更改此设置。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       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.setDragToColumn(false);
       boolean canDragToColumn = field.getDragToColumn();
       
      Returns:
      如果该字段可以拖动到列位置,则为 true;否则为 false。
    • setDragToColumn

      void setDragToColumn(boolean value)
      设置指定字段是否可以拖动到列位置。

      此属性指示是否可以将该字段移动到数据透视表报表的列区域。默认值为 true。使用此方法可更改此设置。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       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.setDragToColumn(false);
       
      Parameters:
      value - 如果该字段可以拖动到列位置,则为 true;否则为 false。
    • getDragToData

      boolean getDragToData()
      获取指定字段是否可以拖动到数据位置。

      此属性指示该字段是否可以移动到 PivotTable 报告的数据区域中。默认值为 true。使用 setDragToData(boolean) 可更改此设置。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Amount");
       field.setDragToData(false);
       boolean canDragToData = field.getDragToData();
       
      Returns:
      如果字段可以拖动到数据位置,则为 true;否则为 false。
    • setDragToData

      void setDragToData(boolean value)
      设置指定字段是否可以拖动到数据位置。

      此属性指示该字段是否可以移动到 PivotTable 报告的数据区域中。默认值为 true。使用此方法可更改此设置。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Amount");
       field.setDragToData(false);
       
      Parameters:
      value - 如果字段可以拖动到数据位置,则为 true;否则为 false。
    • getDragToHide

      boolean getDragToHide()
      获取该字段是否可通过拖离 PivotTable 报表来隐藏。

      此属性指示用户是否可以通过将该字段拖走来将其从 PivotTable 报表中移除。默认值为 true。使用 setDragToHide(boolean) 可更改此设置。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       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.setDragToHide(false);
       boolean canDragToHide = field.getDragToHide();
       
      Returns:
      如果该字段可以通过拖离 PivotTable 报表来隐藏,则为 true;否则为 false。
    • setDragToHide

      void setDragToHide(boolean value)
      设置该字段是否可通过拖离 PivotTable 报表来隐藏。

      此属性指示用户是否可以通过将该字段拖走来将其从 PivotTable 报表中移除。默认值为 true。使用此方法可更改此设置。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       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.setDragToHide(false);
       
      Parameters:
      value - 如果字段可通过拖出 PivotTable 报告来隐藏,则为 true;否则为 false。
    • getDragToPage

      boolean getDragToPage()
      获取字段是否可以拖动到页位置。

      默认值为 true。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Region");
       field.setDragToPage(false);
       boolean canDragToPage = field.getDragToPage();
       
      Returns:
      如果字段可以拖动到页位置,则为 true;否则为 false。
    • setDragToPage

      void setDragToPage(boolean value)
      设置该字段是否可以拖动到页面位置。

      默认值为 true。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Region");
       field.setDragToPage(false);
       
      Parameters:
      value - 如果该字段可以拖动到页面位置,则为 true;否则为 false。
    • getDragToRow

      boolean getDragToRow()
      获取字段是否可以拖动到行位置。

      此属性确定是否允许将字段移动到 PivotTable 中的行区域。默认值为 true。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Region");
       boolean canDragToRow = field.getDragToRow();
       
      Returns:
      如果字段可以拖动到行位置,则为 true;否则为 false。
    • setDragToRow

      void setDragToRow(boolean value)
      设置字段是否可以拖动到行位置。

      此属性确定是否允许将字段移动到 PivotTable 中的行区域。默认值为 true。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 100},
           {"West", "Pear", 200},
           {"East", "Pear", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Region");
       field.setDragToRow(true);
       
      Parameters:
      value - 如果字段可以拖动到行位置,则为 true;否则为 false。
    • getEnableMultiplePageItems

      boolean getEnableMultiplePageItems()
      获取该字段是否可以在页面字段中选择多个项目。

      此属性适用于放置在页面区域中的 PivotTable 字段。默认值为 false。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Date", "Amount"},
           {"2024-01", 120},
           {"2024-02", 150},
           {"2024-03", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField pageField = pivotTable.getPivotFields().get("Date");
       pageField.setOrientation(PivotFieldOrientation.PageField);
       boolean allowMultipleItems = pageField.getEnableMultiplePageItems();
       
      Returns:
      如果该字段可以在页面字段中选择多个项目,则为 true;否则为 false。
    • setEnableMultiplePageItems

      void setEnableMultiplePageItems(boolean value)
      设置字段是否可以在页字段中选择多个项。

      此属性适用于放置在页区域中的 PivotTable 字段。默认值为 false。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Date", "Amount"},
           {"2024-01", 120},
           {"2024-02", 150},
           {"2024-03", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField pageField = pivotTable.getPivotFields().get("Date");
       pageField.setOrientation(PivotFieldOrientation.PageField);
       pageField.setEnableMultiplePageItems(true);
       
      Parameters:
      value - 如果字段可以在页字段中选择多个项,则为 true;否则为 false。
    • getFormula

      String getFormula()
      获取数据透视表字段的公式,该公式采用 A1 样式表示法并使用宏语言。

      此属性返回与字段关联的公式文本。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Banana", 200},
           {"Orange", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField field = pivotTable.getCalculatedFields().add("TotalAmount", "=Amount*2");
       String formula = field.getFormula();
       
      Returns:
      采用 A1 样式表示法并使用宏语言的公式字符串。如果没有与字段关联的公式,则返回 null。
    • setFormula

      void setFormula(String value)
      以 A1 样式表示法并使用宏的语言设置 PivotTable 字段的公式。

      此属性设置与该字段关联的公式文本。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Banana", 200},
           {"Orange", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField field = pivotTable.getCalculatedFields().add("TotalAmount", "=Amount*2");
       field.setFormula("=Amount*3");
       
      Parameters:
      value - 采用 A1 样式表示法并使用宏语言的公式字符串。如果没有与该字段关联的公式,则设置为 null。
    • getFunction

      ConsolidationFunction getFunction()
      获取此 PivotTable 字段使用的汇总函数。

      此属性仅适用于数据字段。使用它可确定字段是否通过求和、计数或平均值等函数汇总源值。若要更改汇总函数,请参见 setFunction(ConsolidationFunction)。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Fruit", 10},
           {"Fruit", 20},
           {"Drink", 5}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField dataField = pivotTable.addDataField(pivotTable.getPivotFields().get("Amount"), "Sum of Amount", ConsolidationFunction.Sum);
       ConsolidationFunction function = dataField.getFunction();
       
      Returns:
      用于汇总 PivotTable 字段的 ConsolidationFunction。
    • setFunction

      void setFunction(ConsolidationFunction value)
      设置用于汇总 PivotTable 字段的函数。

      此方法仅适用于数据字段。使用 ConsolidationFunction 值(例如 ConsolidationFunction.Sum、 ConsolidationFunction.Count 或 ConsolidationFunction.Average)可控制字段值的聚合方式。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Fruit", 120},
           {"Fruit", 80},
           {"Drink", 50}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       pivotTable.getDataFields().get("Sum of Amount").setFunction(ConsolidationFunction.Average);
       
      Parameters:
      value - 用于汇总 PivotTable 数据字段的汇总函数。
    • getLayoutBlankLine

      boolean getLayoutBlankLine()
      获取是否在数据透视表报表中于此行字段后插入空白行。

      此属性适用于放置在数据透视表行区域中的 PivotFields。默认值为 false。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Apple", 200},
           {"Banana", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"));
       IPivotField field = pivotTable.getPivotFields().get("Product");
       field.setOrientation(PivotFieldOrientation.RowField);
       field.setLayoutBlankLine(true);
       boolean blankLine = field.getLayoutBlankLine();
       
      Returns:
      如果在数据透视表报表中于此行字段后插入空白行,则为 true;否则为 false。
    • setLayoutBlankLine

      void setLayoutBlankLine(boolean value)
      设置是否在数据透视表报告中的此行字段后插入空行。

      此属性适用于放置在数据透视表行区域中的 PivotFields。默认值为 false。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Apple", 200},
           {"Banana", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"));
       IPivotField field = pivotTable.getPivotFields().get("Product");
       field.setOrientation(PivotFieldOrientation.RowField);
       field.setLayoutBlankLine(true);
       
      Parameters:
      value - 如果在数据透视表报告中的此行字段后插入空行,则为 true;否则为 false。
    • getLayoutCompactRow

      boolean getLayoutCompactRow()
      获取当此 PivotField 放置在行区域时,是否使用紧凑行布局。

      当此属性为 true 时,多个行 PivotField 中的项目可以显示在单个列中。

      
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Category", "Product", "Amount"},
           {"Fruit", "Apple", 100},
           {"Fruit", "Orange", 80},
           {"Vegetables", "Carrot", 60},
           {"Vegetables", "Celery", 40}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"));
       pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
       IPivotField field = pivotTable.getPivotFields().get("Product");
       field.setOrientation(PivotFieldOrientation.RowField);
       field.setLayoutCompactRow(true);
       boolean compactRow = field.getLayoutCompactRow();
       
      Returns:
      如果在选择行时,PivotField 以紧凑行布局显示,则为 true;否则为 false。
    • setLayoutCompactRow

      void setLayoutCompactRow(boolean value)
      设置此 PivotField 放置在行区域中时是否使用紧凑行布局。

      当此属性为 true 时,来自多个行 PivotField 的项可以显示在单列中。

      
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Category", "Product", "Amount"},
           {"Fruit", "Apple", 100},
           {"Fruit", "Orange", 80},
           {"Vegetables", "Carrot", 60},
           {"Vegetables", "Celery", 40}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"));
       pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
       IPivotField field = pivotTable.getPivotFields().get("Product");
       field.setOrientation(PivotFieldOrientation.RowField);
       field.setLayoutCompactRow(true);
       
      Parameters:
      value - 如果选择行时 PivotField 以紧凑行布局显示,则为 true;否则为 false。
    • getLayoutForm

      LayoutFormType getLayoutForm()
      获取指定 PivotTable 项的显示方式。

      使用此属性可确定该字段是以表格格式显示还是以大纲格式显示。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Beverages", 100},
           {"Beverages", 200},
           {"Snacks", 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);
       field.setLayoutForm(LayoutFormType.Outline);
       LayoutFormType layoutForm = field.getLayoutForm();
       
      Returns:
      PivotTable 字段的布局形式,例如 LayoutFormType.Tabularor LayoutFormType.Outline。
    • setLayoutForm

      void setLayoutForm(LayoutFormType value)
      设置指定数据透视表项的显示方式,可以采用表格格式或大纲格式。

      使用 LayoutFormType.Tabular 以表格形式显示该字段,或使用LayoutFormType.Outline以大纲形式显示。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Fruit", 120},
           {"Fruit", 80},
           {"Vegetables", 95}
       });
       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);
       field.setLayoutForm(LayoutFormType.Outline);
       
      Parameters:
      value - 要应用于数据透视表字段的布局形式,例如LayoutFormType.Tabular或 LayoutFormType.Outline。
    • getLayoutSubtotalLocation

      SubtotalLocationType getLayoutSubtotalLocation()
      获取 PivotTable 字段小计相对于指定字段的位置。

      使用此方法可确定该字段的小计是显示在字段项的上方还是下方。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Beverages", 100},
           {"Beverages", 200},
           {"Snacks", 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);
       field.setLayoutSubtotalLocation(SubtotalLocationType.Bottom);
       SubtotalLocationType location = field.getLayoutSubtotalLocation();
       
      Returns:
      表示小计是显示在指定字段上方还是下方的 SubtotalLocationType 值。
    • setLayoutSubtotalLocation

      void setLayoutSubtotalLocation(SubtotalLocationType value)
      设置此 PivotTable 字段的小计显示位置。

      使用 SubtotalLocationType.Top 可在字段项上方显示小计,或使用 SubtotalLocationType.Bottom 在字段项下方显示小计。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Beverages", 100},
           {"Beverages", 200},
           {"Snacks", 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);
       field.setLayoutSubtotalLocation(SubtotalLocationType.Bottom);
       
      Parameters:
      value - 字段的小计位置。
    • getName

      String getName()
      获取对象的名称。

      使用此方法可获取 PivotTable 报表中字段的当前名称。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Fruit", 120},
           {"Drink", 50},
           {"Fruit", 80}
       });
       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");
       String name = field.getName();
       
      Returns:
      对象的名称。
    • setName

      void setName(String value)
      设置对象的名称。

      使用此方法可设置 PivotTable 报告中字段的名称。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Fruit", 120},
           {"Drink", 50},
           {"Fruit", 80}
       });
       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.setName("Product Category");
       
      Parameters:
      value - 对象的名称。
    • getNumberFormat

      String getNumberFormat()
      获取数据透视表字段的数字格式代码。

      返回的字符串对应于 setNumberFormat(String) 分配的格式代码,并用于在 PivotTable 报告中显示字段值。

      
       Object[][] sourceData = new Object[][] {
           {"Category", "Amount"},
           {"Fruit", 1200},
           {"Fruit", 800},
           {"Vegetables", 600}
       };
       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 amountField = pivotTable.getPivotFields().get("Amount");
       amountField.setOrientation(PivotFieldOrientation.DataField);
       amountField.setNumberFormat("$#,##0.00");
       String numberFormat = amountField.getNumberFormat();
       
      Returns:
      数据透视表字段的数字格式代码。
    • setNumberFormat

      void setNumberFormat(String value)
      设置数据透视字段的数字格式代码。
      
       Object[][] sourceData = new Object[][] {
           {"Category", "Amount"},
           {"Fruit", 1200},
           {"Fruit", 800},
           {"Vegetables", 600}
       };
       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 amountField = pivotTable.getPivotFields().get("Amount");
       amountField.setOrientation(PivotFieldOrientation.DataField);
       amountField.setNumberFormat("$#,##0.00");
       
      Parameters:
      value - 数据透视字段的数字格式代码。
    • getOrientation

      PivotFieldOrientation getOrientation()
      获取字段在指定 PivotTable 报告中的位置。

      使用此方法可确定字段当前放置在 PivotTable 的行、列、页、数据或隐藏区域中。

      
       Object[][] sourceData = new Object[][] {
           {"Product", "Category", "Amount"},
           {"Apple", "Fruit", 100},
           {"Pear", "Fruit", 200}
       };
       worksheet.getRange("A1:C3").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "pivotTable1");
       IPivotField field = pivotTable.getPivotFields().get("Category");
       field.setOrientation(PivotFieldOrientation.RowField);
       PivotFieldOrientation orientation = field.getOrientation();
       
      Returns:
      指示字段在 PivotTable 报告中位置的 PivotFieldOrientation 值。
    • setOrientation

      void setOrientation(PivotFieldOrientation value)
      设置字段在指定数据透视表报告中的位置。

      使用此方法可将字段放置在数据透视表的行、列、页或数据区域中。

      
       Object[][] sourceData = {
           {"Category", "Product", "Amount"},
           {"Fruit", "Apple", 100},
           {"Fruit", "Orange", 200}
       };
       worksheet.getRange("A1:C3").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       IPivotField pivotField = pivotTable.getPivotFields().get("Category");
       pivotField.setOrientation(PivotFieldOrientation.RowField);
       
      Parameters:
      value - 指定字段在数据透视表报告中放置位置的 PivotFieldOrientation。
    • getPosition

      int getPosition()
      获取字段在其当前方向下的字段中的位置。

      该位置确定字段在其方向区域中的顺序,例如行字段、列字段、页字段或数据字段。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Category", "Product", "Amount"},
           {"Fruit", "Apple", 100},
           {"Fruit", "Orange", 80},
           {"Snacks", "Cookie", 60}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Category");
       field.setOrientation(PivotFieldOrientation.RowField);
       field.setPosition(0);
       int position = field.getPosition();
       
      Returns:
      字段在其当前方向中的从零开始的位置。
    • setPosition

      void setPosition(int value)
      设置字段在其当前方向下的字段中的位置。

      该位置确定字段在其方向区域中的顺序,例如行字段、列字段、页字段或数据字段。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Category", "Product", "Amount"},
           {"Fruit", "Apple", 100},
           {"Fruit", "Orange", 80},
           {"Snacks", "Cookie", 60}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       IPivotField field = pivotTable.getPivotFields().get("Category");
       field.setOrientation(PivotFieldOrientation.RowField);
       field.setPosition(0);
       
      Parameters:
      value - 字段在其当前方向中的从零开始的位置。
    • getRepeatLabels

      boolean getRepeatLabels()
      获取数据透视表中指定 IPivotField 的项目标签是否重复显示。

      使用此属性可确定在数据透视表布局中是否显示该字段的重复项目标签。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Product"},
           {"Fruit", "Apple"},
           {"Fruit", "Orange"},
           {"Drink", "Tea"}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"));
       IPivotField field = pivotTable.getPivotFields().get("Category");
       field.setOrientation(PivotFieldOrientation.RowField);
       field.setRepeatLabels(true);
       boolean repeatLabels = field.getRepeatLabels();
       
      Returns:
      如果项目标签重复显示,则为 true;否则为 false。
    • setRepeatLabels

      void setRepeatLabels(boolean value)
      设置是否在数据透视表中为指定的 IPivotField 重复项标签。

      使用此属性可设置是否在数据透视表布局中显示该字段的重复项标签。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Product"},
           {"Fruit", "Apple"},
           {"Fruit", "Orange"},
           {"Drink", "Tea"}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"));
       IPivotField field = pivotTable.getPivotFields().get("Category");
       field.setOrientation(PivotFieldOrientation.RowField);
       field.setRepeatLabels(true);
       
      Parameters:
      value - 如果重复项标签,则为 true;否则为 false。
    • getShowAllItems

      boolean getShowAllItems()
      获取是否显示 PivotTable 报告中的所有项,即使它们不包含汇总数据。

      默认值为 false。当此属性为 true 时,对于 PivotField,仍会显示没有汇总值的项。

      
       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("Category");
       field.setShowAllItems(true);
       boolean showAllItems = field.getShowAllItems();
       
      Returns:
      如果显示 PivotTable 报告中的所有项,即使它们不包含汇总数据,则为 true;否则为 false。
    • setShowAllItems

      void setShowAllItems(boolean value)
      设置是否显示 PivotTable 报告中的所有项,即使它们不包含汇总数据。

      默认值为 false。当此属性为 true 时,对于 PivotField,仍会显示没有汇总值的项。

      
       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("Category");
       field.setShowAllItems(true);
       
      Parameters:
      value - 如果显示 PivotTable 报告中的所有项,即使它们不包含汇总数据,则为 true;否则为 false。
    • getSourceName

      String getSourceName()
      获取字段在原始源数据中显示的名称。

      此值标识 PivotTable 报告的底层源字段。如果字段已使用 setName(String) 重命名,则它可能不同于 getName() 返回的当前显示名称。

      
       Object[][] sourceData = new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Pear", 200}
       };
       worksheet.getRange("G1:H3").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("G1:H3"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("A1"), "PivotTable1");
       IPivotField field = pivotTable.getPivotFields().get("Product");
       field.setName("Item");
       String sourceName = field.getSourceName();
       
      Returns:
      原始源字段名称。
    • getSubtotals

      EnumSet<SubtotalType> getSubtotals()
      获取当前为此 PivotField 显示的小计类型组合。

      此方法仅对非数据字段有效。使用它可检查该字段启用了哪些 SubtotalType 值。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Beverages", 100},
           {"Beverages", 200},
           {"Snacks", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "pivotTable1");
       IPivotField categoryField = pivotTable.getPivotFields().get("Category");
       categoryField.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       categoryField.setSubtotals(EnumSet.of(SubtotalType.Sum, SubtotalType.Count));
       EnumSet<SubtotalType> subtotals = categoryField.getSubtotals();
       
      Returns:
      当前为该字段显示的小计类型组合。
    • setSubtotals

      void setSubtotals(EnumSet<SubtotalType> value)
      设置当前为此 PivotField 显示的小计类型组合。

      此方法仅对非数据字段有效。使用它可检查该字段已启用哪些 SubtotalType 值。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Category", "Amount"},
           {"Beverages", 100},
           {"Beverages", 200},
           {"Snacks", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "pivotTable1");
       IPivotField categoryField = pivotTable.getPivotFields().get("Category");
       categoryField.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       categoryField.setSubtotals(EnumSet.of(SubtotalType.Sum, SubtotalType.Count));
       
      Parameters:
      value - 当前为该字段显示的小计类型组合。
    • autoSort

      void autoSort(SortOrder Order, String Field)
      建立 PivotTable 报告的自动字段排序规则。

      此方法使用指定的排序顺序和指定的排序键字段对当前 PivotField 中的项排序。Field 参数必须是排序键字段的唯一源名称,如 getSourceName() 返回的名称,而不是显示的字段名称。

      示例:

      
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Product", "Region", "Amount"},
           {"Apple", "East", 120},
           {"Orange", "West", 80},
           {"Apple", "West", 150},
           {"Orange", "East", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       IPivotField fieldRegion = pivotTable.getPivotFields().get("Region");
       fieldRegion.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.addDataField(pivotTable.getPivotFields().get("Amount"), "Sum of Amount", ConsolidationFunction.Sum);
       fieldRegion.autoSort(SortOrder.Descending, pivotTable.getPivotFields().get("Amount").getSourceName());
       
      Parameters:
      Order - 要应用的排序顺序。
      Field - 排序键字段的唯一源名称,如 getSourceName() 返回的名称;不要使用显示的字段名称。
    • autoSort

      void autoSort(SortOrder Order)
      为 PivotTable 字段建立自动字段排序规则。

      使用此方法可对 PivotTable 报表中的当前字段应用自动升序或降序排序。

      
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Product", "Region", "Amount"},
           {"Apple", "East", 120},
           {"Orange", "West", 80},
           {"Apple", "West", 150},
           {"Orange", "East", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       IPivotField fieldRegion = pivotTable.getPivotFields().get("Region");
       fieldRegion.setOrientation(PivotFieldOrientation.RowField);
       fieldRegion.autoSort(SortOrder.Descending);
       
      Parameters:
      Order - 要应用的排序顺序。不得为 null。
    • clearAllFilters

      void clearAllFilters()
      删除当前应用于此 PivotField 的所有筛选器。

      此方法会从 getPivotFilters() 集合中删除所有筛选器,并清除应用于该字段的任何手动筛选。如果该字段位于报告筛选区域,则所选项会重置为默认项。

      
       Object[][] sourceData = new Object[][] {
           {"Product", "Amount"},
           {"Example Speaker", 4270},
           {"Example TV", 2626},
           {"Example Mobile", 9062}
       };
       worksheet.getRange("G1:H4").setValue(sourceData);
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("G1:H4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("A1"), "pivottable1");
       IPivotField field = pivotTable.getPivotFields().get("Product");
       field.setOrientation(PivotFieldOrientation.RowField);
       field.getPivotFilters().add(PivotFilterType.CaptionContains, "Example");
       field.clearAllFilters();
       
    • group

      void group(PivotFieldDateGroupOptions options)
      按日期或时间单位对 PivotField 进行分组。

      使用 PivotFieldDateGroupOptions 可以指定分组范围以及用于创建分组 PivotField 的日期或时间单位。该字段必须是未计算的源字段,且其源项必须为日期值。

      
       Workbook workbook = new Workbook();
       workbook.getOptions().getData().setAutomaticGroupDateTimeInPivotTable(false);
       IWorksheet worksheet = workbook.getWorksheets().get(0);
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Order Date", "Region", "Amount"},
           {java.time.LocalDateTime.of(2024, 1, 5, 0, 0), "East", 10},
           {java.time.LocalDateTime.of(2024, 1, 18, 0, 0), "West", 20},
           {java.time.LocalDateTime.of(2024, 2, 2, 0, 0), "East", 30},
           {java.time.LocalDateTime.of(2024, 2, 25, 0, 0), "West", 40}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       IPivotField orderDateField = pivotTable.getPivotFields().get("Order Date");
       orderDateField.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       PivotFieldDateGroupOptions options = new PivotFieldDateGroupOptions();
       options.setGroupBy(Collections.singletonList(PivotFieldDateGroupBy.Months));
       options.setAutoStart(true);
       options.setAutoEnd(true);
       orderDateField.group(options);
       String groupedFieldName = pivotTable.getRowFields().get(0).getName();
       
      Parameters:
      options - 日期分组设置。不得为 null。
      Throws:
      IllegalArgumentException - 如果 options 为 null。
      UnsupportedOperationException - 如果此字段无法按日期分组。
    • group

      void group(PivotFieldNumberGroupOptions options)
      将 PivotField 分组为数值范围。

      使用 PivotFieldNumberGroupOptions 可以指定分组范围以及用于创建每个生成分组的数值间隔。该字段必须是未计算的源字段,且其源项必须为数值。

      
       Workbook workbook = new Workbook();
       IWorksheet worksheet = workbook.getWorksheets().get(0);
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Order ID", "Region", "Amount"},
           {10348, "East", 10},
           {10362, "East", 20},
           {10375, "West", 30},
           {10391, "West", 40}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       IPivotField orderIdField = pivotTable.getPivotFields().get("Order ID");
       orderIdField.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       PivotFieldNumberGroupOptions options = new PivotFieldNumberGroupOptions();
       options.setStart(10348d);
       options.setEnd(10407d);
       options.setAutoStart(false);
       options.setAutoEnd(false);
       options.setInterval(20);
       orderIdField.group(options);
       
      Parameters:
      options - 数值分组设置。不得为 null。
      Throws:
      IllegalArgumentException - 如果 options 为 null。
      UnsupportedOperationException - 如果此字段无法分组为数值范围。
    • group

      void group(PivotFieldCustomGroupOptions options)
      从 PivotField 中的 PivotItem 创建自定义分组。

      使用 PivotFieldCustomGroupOptions 可以指定源 PivotItem 名称、可选显示名称,以及是否将生成的分组字段自动添加到数据透视表布局。源名称、项名称和标题匹配时不区分大小写。

      
       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");
       IPivotField productField = pivotTable.getPivotFields().get("Product");
       productField.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       PivotFieldCustomGroupOptions options = new PivotFieldCustomGroupOptions();
       options.setName("Fruit Group");
       options.setItems(java.util.Arrays.asList("Apple", "Banana"));
       productField.group(options);
       
      Parameters:
      options - 自定义分组设置。不得为 null。
      Throws:
      IllegalArgumentException - 如果 options 为 null。
      UnsupportedOperationException - 如果此字段无法分组。
    • ungroup

      void ungroup()
      从数据透视表字段中移除分组。

      移除分组后,数据透视表字段将使用 PivotCache 中的原始源项。

      
       Workbook workbook = new Workbook();
       workbook.getOptions().getData().setAutomaticGroupDateTimeInPivotTable(false);
       IWorksheet worksheet = workbook.getWorksheets().get(0);
       worksheet.getRange("A1:C5").setValue(new Object[][] {
           {"Order Date", "Region", "Amount"},
           {java.time.LocalDateTime.of(2024, 1, 5, 0, 0), "East", 10},
           {java.time.LocalDateTime.of(2024, 1, 18, 0, 0), "West", 20},
           {java.time.LocalDateTime.of(2024, 2, 2, 0, 0), "East", 30},
           {java.time.LocalDateTime.of(2024, 2, 25, 0, 0), "West", 40}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       IPivotField orderDateField = pivotTable.getPivotFields().get("Order Date");
       orderDateField.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       PivotFieldDateGroupOptions options = new PivotFieldDateGroupOptions();
       options.setGroupBy(Collections.singletonList(PivotFieldDateGroupBy.Months));
       orderDateField.group(options);
       orderDateField.ungroup();
       
      Throws:
      IllegalStateException - 如果此数据透视表字段未分组。
    • clearManualFilter

      void clearManualFilter()
      清除 PivotField 的手动筛选。

      此方法会将数据透视表中该字段的所有项目的可见状态设置为可见。对于 OLAP 数据透视表,它还会清空手动筛选使用的隐藏项目列表和可见项目列表。

      
       worksheet.getRange("A1:B5").setValue(new Object[][] {
           {"Region", "Amount"},
           {"East", 120},
           {"West", 80},
           {"East", 150},
           {"South", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
       IPivotField fieldRegion = pivotTable.getPivotFields().get("Region");
       fieldRegion.setOrientation(PivotFieldOrientation.RowField);
       fieldRegion.getPivotItems().get("West").setVisible(false);
       fieldRegion.clearManualFilter();
       
    • getPivotItems

      IPivotItems getPivotItems()
      获取此 PivotTable 字段中所有可见和隐藏项目的集合。

      使用此集合可访问各个字段项,包括当前因手动筛选而隐藏的项目。

      
       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);
       
      Returns:
      此字段中所有可见和隐藏项目的集合。
    • getCalculatedItems

      ICalculatedItems getCalculatedItems()
      获取此 IPivotField 的计算项集合。

      返回的 ICalculatedItems 集合表示为当前 PivotTable 字段定义的所有计算项,可用于访问或添加计算项。

      
       worksheet.getRange("A1:C4").setValue(new Object[][] {
           {"Region", "Product", "Amount"},
           {"East", "Apple", 120},
           {"East", "Banana", 80},
           {"West", "Apple", 90}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
       pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.ColumnField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       ICalculatedItems calculatedItems = pivotTable.getPivotFields().get("Product").getCalculatedItems();
       
      Returns:
      当前 PivotTable 字段的 ICalculatedItems 集合。
    • getPivotFilters

      IPivotFilters getPivotFilters()
      获取此 IPivotField 的数据透视筛选器集合。

      返回的 IPivotFilters 集合包含为当前数据透视字段定义的标签、日期和值筛选器,可用于添加或访问筛选器。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Mi Phone", 100},
           {"Camera", 200},
           {"Mi Band", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField productField = pivotTable.getPivotFields().get("Product");
       productField.setOrientation(PivotFieldOrientation.RowField);
       IPivotFilters filters = productField.getPivotFilters();
       filters.add(PivotFilterType.CaptionContains, "Mi");
       
      Returns:
      当前数据透视字段的 IPivotFilters 集合。
    • clearLabelFilter

      void clearLabelFilter()
      清除此数据透视字段中的所有标签筛选器或日期筛选器。

      此方法会移除存储在数据透视字段的 getPivotFilters() 集合中的基于标签的筛选条件。使用此方法可保持值筛选器等其他筛选类型不变。

      
       Object[][] sourceData = new Object[][] {
           {"Product", "Amount"},
           {"Mi Phone", 100},
           {"Camera", 200},
           {"Mi Band", 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 productField = pivotTable.getPivotFields().get("Product");
       productField.setOrientation(PivotFieldOrientation.RowField);
       productField.getPivotFilters().add(PivotFilterType.CaptionContains, "Mi");
       productField.clearLabelFilter();
       
    • clearValueFilter

      void clearValueFilter()
      清除此数据透视字段中的所有值筛选器。

      此方法会从数据透视字段的 getPivotFilters() 集合中移除基于值的筛选条件。使用此方法可清除值筛选器,而不移除标签筛选器或手动筛选。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Banana", 200},
           {"Apple", 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField productField = pivotTable.getPivotFields().get("Product");
       productField.setOrientation(PivotFieldOrientation.RowField);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       PivotFilterOptions options = new PivotFilterOptions();
       options.setAppliedDataField(0);
       productField.getPivotFilters().add(PivotFilterType.ValueGreaterThan, 120, null, options);
       productField.clearValueFilter();