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

IPivotFilters

Interface IPivotFilters

All Superinterfaces:
Iterable<IPivotFilter>

public interface IPivotFilters extends Iterable<IPivotFilter>
表示数据透视字段中所有数据透视筛选器的集合。

此接口提供对为数据透视字段定义的标签、日期和值筛选器的访问。使用它可以添加新筛选器、按索引检索现有筛选器,以及遍历当前 IPivotFilter 对象。


 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");
 
  • Method Details

    • size

      int size()
      获取集合中的数据透视表筛选器数量。

      此方法返回已通过 IPivotField.getPivotFilters() 添加到数据透视字段的筛选器当前数量。

      
       Object[][] sourceData = new Object[][] {
           {"Product", "Amount"},
           {"Example Speaker", 4270},
           {"Example TV", 2626},
           {"Example Phone", 2417}
       };
       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 fieldProduct = pivotTable.getPivotFields().get("Product");
       fieldProduct.setOrientation(PivotFieldOrientation.RowField);
       fieldProduct.getPivotFilters().add(PivotFilterType.CaptionContains, "mi");
       int count = fieldProduct.getPivotFilters().size();
       
      Returns:
      集合中的数据透视表筛选器数量。
    • get

      IPivotFilter get(int index)
      获取指定索引处的数据透视筛选器。

      使用此方法可访问已添加到当前 IPivotFilters 集合的筛选器。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Pear", 200},
           {"Avocado", 150}
       });
       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);
       pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
       productField.getPivotFilters().add(PivotFilterType.CaptionContains, "A");
       IPivotFilter filter = productField.getPivotFilters().get(0);
       
      Parameters:
      index - 要获取的数据透视筛选器的从零开始的索引。
      Returns:
      指定索引处的数据透视筛选器。
    • add

      IPivotFilter add(PivotFilterType type, Object value1, Object value2, PivotFilterOptions options)
      向 PivotFilters 集合添加新筛选器。

      使用此方法可向数据透视字段添加标签、值、日期或前 10 项筛选器。 value1、 value2 和 options 的含义取决于指定的 PivotFilterType。对于值筛选器,请先在 PivotFilterOptions 中设置应用的数据字段,然后再添加筛选器。

      
       Object[][] sourceData = new Object[][] {
           {"Product", "Category", "Amount"},
           {"Example Speaker", "Consumer Electronics", 4270},
           {"Example Camera", "Consumer Electronics", 8239},
           {"Example TV", "Consumer Electronics", 2626},
           {"Example Smartphone", "Mobile", 8250}
       };
       worksheet.getRange("A1:C5").setValue(sourceData);
       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);
       IPivotField amountField = pivotTable.getPivotFields().get("Amount");
       amountField.setOrientation(PivotFieldOrientation.DataField);
       PivotFilterOptions options = new PivotFilterOptions();
       options.setAppliedDataField(0);
       IPivotFilter filter = productField.getPivotFilters().add(PivotFilterType.ValueGreaterThan, 7000, null, options);
       IPivotField dataField = filter.getDataField();
       
      Parameters:
      type - 要添加的筛选类型。
      value1 - 第一个筛选值。此值是可选的,其含义取决于筛选类型;当筛选类型不需要它时,允许为 null。
      value2 - 第二个筛选值。此值是可选的,通常由需要第二个边界值的筛选类型使用;其他情况下允许为 null。
      options - 附加筛选器设置。如果不需要额外设置,请使用 null。
      Returns:
      添加的数据透视筛选器。
    • add

      IPivotFilter add(PivotFilterType type, Object value1, Object value2)
      向数据透视表筛选器集合添加一个新筛选器。

      使用此方法可以创建需要两个条件值的数据透视表筛选器,例如介于或不介于条件。此重载会调用 add(PivotFilterType,Object,Object,PivotFilterOptions),并为 options 参数传入 null。

      
       worksheet.getRange("A1:B5").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 120},
           {"Banana", 90},
           {"Carrot", 150},
           {"Dates", 110}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B5"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField productField = pivotTable.getPivotFields().get("Product");
       productField.setOrientation(PivotFieldOrientation.RowField);
       IPivotFilter filter = productField.getPivotFilters().add(PivotFilterType.CaptionBetween, "Apple", "Carrot");
       
      Parameters:
      type - 要添加的筛选类型。
      value1 - 第一个筛选器值。其含义取决于 type;当指定的筛选类型不需要第一个值时,允许为 null。
      value2 - 第二个筛选器值。其含义取决于 type;当指定的筛选类型不需要第二个值时,允许为 null。
      Returns:
      添加的数据透视表筛选器。
    • add

      IPivotFilter add(PivotFilterType type, Object value1)
      向数据透视筛选器集合添加新筛选器。

      使用此方法可创建需要单个条件值的数据透视筛选器,例如由 value1 表示的标题、值或日期条件。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 120},
           {"Banana", 90},
           {"Apricot", 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);
       IPivotFilter filter = productField.getPivotFilters().add(PivotFilterType.CaptionBeginsWith, "A");
       
      Parameters:
      type - 要添加的筛选类型。
      value1 - 第一个筛选值。其含义取决于 type;如果指定的筛选类型不需要第一个值,则可以为 null。
      Returns:
      添加的数据透视筛选器。
    • add

      向集合添加新的数据透视筛选器。

      此重载会为第一个值、第二个值和筛选器选项传递 null。将它与不需要显式条件值的 PivotFilterType 值一起使用,例如月份、季度或相对日期筛选器。

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Date", "Amount"},
           {new java.util.GregorianCalendar(2024, 0, 10), 100},
           {new java.util.GregorianCalendar(2024, 1, 12), 200},
           {new java.util.GregorianCalendar(2024, 0, 25), 150}
       });
       IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
       IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
       IPivotField dateField = pivotTable.getPivotFields().get("Date");
       dateField.setOrientation(PivotFieldOrientation.RowField);
       IPivotFilter filter = dateField.getPivotFilters().add(PivotFilterType.M1);
       
      Parameters:
      type - 要添加的筛选类型。必须是无需显式筛选值即可应用的 PivotFilterType;不得为 null。
      Returns:
      添加的数据透视筛选器。