[]
使用此类可以在通过 IPivotFilters.add(PivotFilterType,Object,Object,PivotFilterOptions) 添加数据透视表筛选器时提供其他配置。它包含值筛选器、日期筛选器和 Top 10 筛选器使用的设置,例如筛选器名称、描述、引用的数据字段、整天日期匹配以及前几项或后几项选择行为。
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Product", "Amount"},
{"Example Speaker", 4270},
{"Example Camera", 8239},
{"Example TV", 2626},
{"Example Smartphone", 8250}
});
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);
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();
intbooleangetName()booleanvoidsetAppliedDataField(int appliedDataField) voidsetDescription(String description) voidsetIsTop10Type(boolean isTop10Type) voidvoidsetWholeDayFilter(boolean wholeDayFilter) 返回分配给此 PivotFilterOptions 实例的名称。
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Product", "Amount"},
{"Example Speaker", 4270},
{"Example Camera", 8239},
{"Example TV", 2626},
{"Example Smartphone", 8250}
});
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);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
PivotFilterOptions options = new PivotFilterOptions();
options.setName("HighValueSalesFilter");
productField.getPivotFilters().add(PivotFilterType.ValueGreaterThan, 7000, null, options);
String name = options.getName();
null。设置分配给此 PivotFilterOptions 实例的名称。
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Product", "Amount"},
{"Example Speaker", 4270},
{"Example Camera", 8239},
{"Example TV", 2626},
{"Example Smartphone", 8250}
});
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);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
PivotFilterOptions options = new PivotFilterOptions();
options.setName("HighValueSalesFilter");
IPivotFilter filter = productField.getPivotFilters().add(PivotFilterType.ValueGreaterThan, 7000, null, options);
name - 筛选器的名称。如果未设置名称,则设置为 null。返回通过 setDescription(String) 为此 PivotFilterOptions 实例分配的描述。
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Product", "Amount"},
{"Example Speaker", 4270},
{"Example Camera", 8239},
{"Example TV", 2626},
{"Example Smartphone", 8250}
});
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);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
PivotFilterOptions options = new PivotFilterOptions();
options.setDescription("Shows products with sales above 7000");
productField.getPivotFilters().add(PivotFilterType.ValueGreaterThan, 7000, null, options);
String description = options.getDescription();
null。
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Product", "Amount"},
{"Example Speaker", 4270},
{"Example Camera", 8239},
{"Example TV", 2626},
{"Example Smartphone", 8250}
});
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);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
PivotFilterOptions options = new PivotFilterOptions();
options.setDescription("Shows products with sales above 7000");
IPivotFilter filter = productField.getPivotFilters().add(PivotFilterType.ValueGreaterThan, 7000, null, options);
description - 筛选器的简短描述。如果未设置描述,则设置为 null。指定当前字段按哪个 DataField 筛选。返回的值表示引用的 DataField 在 DataFields 集合中的索引。
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Product", "Amount"},
{"Example Speaker", 4270},
{"Example Camera", 8239},
{"Example TV", 2626},
{"Example Smartphone", 8250}
});
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);
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);
int appliedDataField = options.getAppliedDataField();
IPivotField dataField = filter.getDataField();
指定当前字段按哪个 DataField 筛选。返回的值表示引用的 DataField 在 DataFields 集合中的索引。
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Product", "Amount"},
{"Example Speaker", 4270},
{"Example Camera", 8239},
{"Example TV", 2626},
{"Example Smartphone", 8250}
});
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);
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);
appliedDataField - 引用的 DataField 在 DataFields 集合中的索引。此选项在创建日期筛选器并确定筛选条件是否应按整天而不是按时间匹配时,与 IPivotFilters.add(PivotFilterType,Object,Object,PivotFilterOptions) 一起使用。
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Date", "Amount"},
{new java.util.GregorianCalendar(2024, 0, 1, 8, 30, 0), 100},
{new java.util.GregorianCalendar(2024, 0, 1, 17, 45, 0), 200},
{new java.util.GregorianCalendar(2024, 0, 2, 9, 0, 0), 300}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "DatePivot");
IPivotField dateField = pivotTable.getPivotFields().get("Date");
dateField.setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
PivotFilterOptions options = new PivotFilterOptions();
options.setWholeDayFilter(true);
IPivotFilter filter = dateField.getPivotFilters().add(
PivotFilterType.DateBetween,
new java.util.GregorianCalendar(2024, 0, 1),
new java.util.GregorianCalendar(2024, 0, 1, 23, 59, 59),
options);
boolean wholeDayFilter = filter.getWholeDayFilter();
true;否则返回 false。此选项在创建日期筛选器并确定筛选条件是否应按整天而不是按时间匹配时,与 IPivotFilters.add(PivotFilterType,Object,Object,PivotFilterOptions) 一起使用。
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Date", "Amount"},
{new java.util.GregorianCalendar(2024, 0, 1, 8, 30, 0), 100},
{new java.util.GregorianCalendar(2024, 0, 1, 17, 45, 0), 200},
{new java.util.GregorianCalendar(2024, 0, 2, 9, 0, 0), 300}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "DatePivot");
IPivotField dateField = pivotTable.getPivotFields().get("Date");
dateField.setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
PivotFilterOptions options = new PivotFilterOptions();
options.setWholeDayFilter(true);
IPivotFilter filter = dateField.getPivotFilters().add(
PivotFilterType.DateBetween,
new java.util.GregorianCalendar(2024, 0, 1),
new java.util.GregorianCalendar(2024, 0, 1, 23, 59, 59),
options);
wholeDayFilter - 如果日期筛选器在其筛选条件中使用整天,则为 true;否则为 false。当筛选器配置为选择前 n 个项时,返回 true;当筛选器配置为选择后 n 个项时,返回 false。默认值为 true。
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Product", "Amount"},
{"Example Speaker", 4270},
{"Example Camera", 8239},
{"Example TV", 2626},
{"Example Smartphone", 8250}
});
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);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
PivotFilterOptions options = new PivotFilterOptions();
options.setAppliedDataField(0);
options.setIsTop10Type(false);
IPivotFilter filter = productField.getPivotFilters().add(PivotFilterType.Count, 2, null, options);
boolean bottomItems = !options.getIsTop10Type();
n 个项,则返回 true;如果筛选器选择后 n 个项,则返回 false。当筛选器配置为选择前 n 个项时,设置为 true;当筛选器配置为选择后 n 个项时,设置为 false。默认值为 true。
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Product", "Amount"},
{"Example Speaker", 4270},
{"Example Camera", 8239},
{"Example TV", 2626},
{"Example Smartphone", 8250}
});
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);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
PivotFilterOptions options = new PivotFilterOptions();
options.setAppliedDataField(0);
options.setIsTop10Type(false);
IPivotFilter filter = productField.getPivotFilters().add(PivotFilterType.Count, 2, null, options);
isTop10Type - 如果筛选器选择前 n 个项,则为 true;如果筛选器选择后 n 个项,则为 false。