[]
Iterable<IPivotItem>IPivotItem 对象集合。使用此接口可以访问、添加和移除数据透视字段的计算项。可从 IPivotField.getCalculatedItems() 获取实例。
worksheet.getRange("A1:C4").setValue(new Object[][] {
{"Product", "Category", "Amount"},
{"Apple", "Fruit", 120},
{"Banana", "Fruit", 80},
{"Bran", "Snack", 60}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
ICalculatedItems calculatedItems = pivotTable.getPivotFields().get("Product").getCalculatedItems();
IPivotItem item = calculatedItems.add("TotalFruit", "=Product[Apple] + Product[Banana]");
IPivotItem 对象。get(int index) IPivotItem。IPivotItem 项。intgetCount()IPivotItem 对象数量。voidforEach, iterator, spliteratorIPivotItem 对象数量。此值表示为关联数据透视字段定义的计算项总数。如果集合不包含任何计算项,则返回 0。
worksheet.getRange("A1:B3").setValue(new Object[][] {
{"Region", "Amount"},
{"North", 100},
{"South", 200}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
ICalculatedItems items = pivotTable.getPivotFields().get("Region").getCalculatedItems();
items.add("NorthAndSouth", "=Region[North]+Region[South]");
int count = items.getCount();
IPivotItem 对象数量。IPivotItem。使用此方法可以从 IPivotField.getCalculatedItems() 返回的集合中检索计算项。
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Country", "Amount"},
{"France", 100},
{"Germany", 200},
{"Canada", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.getPivotFields().get("Country").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
ICalculatedItems calculatedItems = pivotTable.getPivotFields().get("Country").getCalculatedItems();
calculatedItems.add("Europe", "=France+Germany");
IPivotItem item = calculatedItems.get(0);
index - 计算项的零基索引。IPivotItem。IPivotItem 项。使用此方法可以从数据透视字段的 ICalculatedItems 集合中检索计算项。
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Status", "Amount"},
{"Pending", 100},
{"Backorder", 200},
{"Shipped", 300}
});
IWorksheet pivotSheet = workbook.getWorksheets().add();
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = pivotSheet.getPivotTables().add(pivotCache, pivotSheet.getRange("A1"));
pivotTable.getPivotFields().get("Status").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
ICalculatedItems calculatedItems = pivotTable.getPivotFields().get("Status").getCalculatedItems();
calculatedItems.add("Open Orders", "=Pending+Backorder");
IPivotItem item = calculatedItems.get("Open Orders");
itemName - 要检索的计算项的名称。IPivotItem。IPivotItem 对象。将计算项添加到从 IPivotField.getCalculatedItems() 获取的数据透视字段计算项集合后,可以使用返回的项访问该计算项。
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Country", "Amount"},
{"France", 100},
{"Germany", 200},
{"Canada", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
IPivotItem item = pivotTable.getPivotFields().get("Country").getCalculatedItems().add("Europe", "=France+Germany");
name - 计算项的名称。formula - 用于定义计算项的公式。IPivotItem。此方法从当前 ICalculatedItems 集合中移除计算项,该集合从 IPivotField.getCalculatedItems() 获取。项名称匹配不区分大小写。如果不存在具有指定名称的计算项,此方法不执行任何操作。
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Status", "Amount"},
{"Pending", 100},
{"Backorder", 200},
{"Shipped", 300}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.getPivotFields().get("Status").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
ICalculatedItems calculatedItems = pivotTable.getPivotFields().get("Status").getCalculatedItems();
calculatedItems.add("Open Orders", "=Pending+Backorder");
calculatedItems.remove("Open Orders");
itemName - 要移除的计算项名称。如果不存在匹配的计算项,则不移除任何项。