[]
An IPivotField is a member of the IPivotFields collection and describes how a source field is used in a PivotTable report, including hidden fields. Use this interface to access field metadata, change field orientation, configure sorting and filtering, and work with row, column, page, or data fields.
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);
voidvoidvoidvoidvoidvoidbooleanIPivotField.PivotFieldCalculation value that represents the type of calculation performed by the specified field.intbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleangetName()IPivotField.intbooleanIPivotField.booleanvoidgroup(PivotFieldCustomGroupOptions options) voidgroup(PivotFieldDateGroupOptions options) voidgroup(PivotFieldNumberGroupOptions options) voidsetBaseField(String value) voidsetBaseItem(String value) voidPivotFieldCalculation value that specifies how the data field is calculated in the PivotTable.voidsetCurrentPage(int value) voidsetDragToColumn(boolean value) voidsetDragToData(boolean value) voidsetDragToHide(boolean value) voidsetDragToPage(boolean value) voidsetDragToRow(boolean value) voidsetEnableMultiplePageItems(boolean value) voidsetFormula(String value) voidsetFunction(ConsolidationFunction value) voidsetLayoutBlankLine(boolean value) voidsetLayoutCompactRow(boolean value) voidsetLayoutForm(LayoutFormType value) voidvoidvoidsetNumberFormat(String value) voidvoidsetPosition(int value) voidsetRepeatLabels(boolean value) IPivotField.voidsetShowAllItems(boolean value) voidsetSubtotals(EnumSet<SubtotalType> value) voidungroup()Returns false when manual filtering has been applied by hiding one or more items. Use clearManualFilter() to restore visibility to all items.
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();
true if no manual filtering is applied and all items in the field are visible; otherwise, false.If automatic sorting is configured by autoSort(SortOrder,String), this method returns the sort key field name that was specified for that rule.
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();
If automatic sorting is configured by autoSort(SortOrder) or autoSort(SortOrder,String), this method returns the SortOrder applied to the field.
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();
This property is valid only for data fields. Use this property together with getCalculation() when the data field is configured to show values by a custom calculation such as 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");
String baseField = dataField.getBaseField();
This property is valid only for data fields. Use this property together with getCalculation() when the data field is configured to show values by a custom calculation such as 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");
value - The name of the base field used for the custom calculation.This property is valid only for data fields. Use this property together with getBaseField() and getCalculation() to determine which item in the base field is used by a custom calculation such as 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();
This property is valid only for data fields. Use this property together with getBaseField() and getCalculation() to determine which item in the base field is used by a custom calculation such as 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");
value - The item name in the base field that is used for the custom calculation.PivotFieldCalculation value that represents the type of calculation performed by the specified field.This property is valid only for data fields.
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();
PivotFieldCalculation value that indicates the type of calculation performed by the field.PivotFieldCalculation value that specifies how the data field is calculated in the PivotTable.This property is valid only for data fields. Use it to change the data field from the default calculation to a custom calculation such as 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);
value - The PivotFieldCalculation value that specifies the calculation type for the data field.This method is valid only for page fields. The returned index is zero-based. A value of -1 indicates that the page field is showing All or multiple items.
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();
-1 if the page field is showing All or multiple items.This method is valid only for page fields. The returned index is zero-based. A value of -1 indicates that the page field is showing All or multiple items.
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);
value - The zero-based index of the current page item for the page field, or -1 if the page field is showing All or multiple items.This property indicates whether the field can be moved into the column area of a PivotTable report. The default value is true. Use setDragToColumn(boolean) to change this setting.
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();
true if the field can be dragged to the column position; otherwise, false.This property indicates whether the field can be moved into the column area of a PivotTable report. The default value is true. Use this method to change this setting.
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);
value - true if the field can be dragged to the column position; otherwise, false.This property indicates whether the field can be moved into the data area of a PivotTable report. The default value is true. Use setDragToData(boolean) to change this setting.
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();
true if the field can be dragged to the data position; otherwise, false.This property indicates whether the field can be moved into the data area of a PivotTable report. The default value is true. Use this method to change this setting.
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);
value - true if the field can be dragged to the data position; otherwise, false.This property indicates whether users can remove the field from the PivotTable report by dragging it away. The default value is true. Use setDragToHide(boolean) to change this setting.
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();
true if the field can be hidden by being dragged off the PivotTable report; otherwise, false.This property indicates whether users can remove the field from the PivotTable report by dragging it away. The default value is true. Use this method to change this setting.
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);
value - true if the field can be hidden by being dragged off the PivotTable report; otherwise, false.The default value is 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();
true if the field can be dragged to the page position; otherwise, false.The default value is 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);
value - true if the field can be dragged to the page position; otherwise, false.This property determines whether the field is allowed to be moved to the row area in a PivotTable. The default value is 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();
true if the field can be dragged to the row position; otherwise, false.This property determines whether the field is allowed to be moved to the row area in a PivotTable. The default value is 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);
value - true if the field can be dragged to the row position; otherwise, false.This property applies to PivotTable fields that are placed in the page area. The default value is 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();
true if the field can have multiple items selected in the page field; otherwise, false.This property applies to PivotTable fields that are placed in the page area. The default value is 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);
value - true if the field can have multiple items selected in the page field; otherwise, false.This property returns the formula text associated with the field.
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();
null if no formula is associated with the field.This property Sets the formula text associated with the field.
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");
value - The formula string in A1-style notation and in the language of the macro. Set null if no formula is associated with the field.This property applies to data fields only. Use it to determine whether the field summarizes source values by functions such as sum, count, or average. See setFunction(ConsolidationFunction) to change the summary function.
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();
ConsolidationFunction used to summarize the PivotTable field.This method applies to data fields only. Use a ConsolidationFunction value such as ConsolidationFunction.Sum, ConsolidationFunction.Count, or ConsolidationFunction.Average to control how the field values are aggregated.
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);
value - The consolidation function used to summarize the PivotTable data field.This property applies to PivotFields placed in the row area of a PivotTable. The default value is 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();
true if a blank row is inserted after this row field in the PivotTable report; otherwise, false.This property applies to PivotFields placed in the row area of a PivotTable. The default value is 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);
value - true if a blank row is inserted after this row field in the PivotTable report; otherwise, false.When this property is true, items from multiple row PivotFields can be displayed in a single column.
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();
true if the PivotField is displayed in compact row layout when rows are selected; otherwise, false.When this property is true, items from multiple row PivotFields can be displayed in a single column.
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);
value - true if the PivotField is displayed in compact row layout when rows are selected; otherwise, false.Use this property to determine whether the field is displayed in table format or outline format.
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();
LayoutFormType.Tabular or LayoutFormType.Outline.Use LayoutFormType.Tabular to display the field in tabular form or LayoutFormType.Outline to display it in outline form.
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);
value - The layout form to apply to the PivotTable field, such as LayoutFormType.Tabular or LayoutFormType.Outline.Use this method to determine whether subtotals for the field are displayed above or below the field items.
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();
SubtotalLocationType value that indicates whether subtotals are displayed above or below the specified field.Use SubtotalLocationType.Top to display subtotals above the field items, or SubtotalLocationType.Bottom to display them below the field items.
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);
value - The subtotal location for the field.Use this method to retrieve the current name of a field in a PivotTable report.
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();
Use this method to set the name of a field in a PivotTable report.
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");
value - The name of the object.The returned string corresponds to the format code assigned by setNumberFormat(String) and is used to display the field's values in the PivotTable report.
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();
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");
value - The number format code for the pivot field.Use this method to determine whether the field is currently placed in the row, column, page, data, or hidden area of the 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();
PivotFieldOrientation value that indicates the field location in the PivotTable report.Use this method to place the field in a row, column, page, or data area of a PivotTable.
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);
value - The PivotFieldOrientation that specifies where the field is placed in the PivotTable report.The position determines the order of the field within its orientation area, such as row fields, column fields, page fields, or data fields.
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();
The position determines the order of the field within its orientation area, such as row fields, column fields, page fields, or data fields.
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);
value - The zero-based position of the field within its current orientation.IPivotField. Use this property to determine whether repeated item labels are shown for the field in the PivotTable layout.
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();
true if item labels are repeated; otherwise, false.IPivotField. Use this property to set whether repeated item labels are shown for the field in the PivotTable layout.
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);
value - true if item labels are repeated; otherwise, false.The default value is false. When this property is true, items without summarized values are still shown for the 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();
true if all items in the PivotTable report are displayed, even when they do not contain summary data; otherwise, false.The default value is false. When this property is true, items without summarized values are still shown for the 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);
value - true if all items in the PivotTable report are displayed, even when they do not contain summary data; otherwise, false.This value identifies the underlying source field for the PivotTable report. It can differ from the current display name returned by getName() if the field has been renamed by using setName(String).
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();
This method is valid only for nondata fields. Use it to inspect which SubtotalType values are enabled for the field.
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();
This method is valid only for nondata fields. Use it to inspect which SubtotalType values are enabled for the field.
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));
value - The combination of subtotal types currently shown for the field.This method sorts the items in the current PivotField by using the specified
sort order and the specified sort key field. The Field argument must
be the unique source name of the sort key field, as returned by getSourceName(),
rather than the displayed field name.
Example:
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());
Order - The sort order to apply.Field - The unique source name of the sort key field, as returned by getSourceName(); do not use the displayed field name.Use this method to apply automatic ascending or descending sorting to the current field in a PivotTable report.
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);
Order - The sort order to apply. Must not be null.This method removes all filters from the getPivotFilters() collection and also clears any manual filtering applied to the field. If the field is in the report filter area, the selected item is reset to the default item.
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();
Use PivotFieldDateGroupOptions to specify the grouped range and the date or time units used to create the grouped PivotField. The field must be an uncalculated source field whose source items are date values.
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();
options - The date grouping settings. Must not be null.IllegalArgumentException - if options is null.UnsupportedOperationException - if this field cannot be grouped by date.Use PivotFieldNumberGroupOptions to specify the grouped range and numeric interval used to create each generated group. The field must be an uncalculated source field whose source items are numeric values.
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);
options - The numeric grouping settings. Must not be null.IllegalArgumentException - if options is null.UnsupportedOperationException - if this field cannot be grouped into numeric ranges.Use PivotFieldCustomGroupOptions to specify the source PivotItem names, optional display name, and whether generated group fields are automatically added to the PivotTable layout. Source names, item names, and captions are matched without case sensitivity.
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);
options - The custom grouping settings. Must not be null.IllegalArgumentException - if options is null.UnsupportedOperationException - if this field cannot be grouped.After grouping is removed, the pivot field uses the original source items from the 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();
IllegalStateException - if this pivot field is not grouped.This method sets the visible state of all items in the field to visible in PivotTables. For OLAP PivotTables, it also clears the hidden and visible item lists used by manual filtering.
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();
Use this collection to access individual field items, including items that are currently hidden by manual filtering.
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);
IPivotField. The returned ICalculatedItems collection represents all calculated items defined for the current PivotTable field and can be used to access or add calculated items.
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();
ICalculatedItems collection for the current PivotTable field.IPivotField. The returned IPivotFilters collection contains the label, date, and value filters defined for the current pivot field and can be used to add or access filters.
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");
IPivotFilters collection for the current pivot field.This method removes the label-based filter criteria stored in the pivot field's getPivotFilters() collection. Use this method when you want to keep other filter types, such as value filters, unchanged.
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();
This method removes value-based filter criteria from the pivot field's getPivotFilters() collection. Use this method when you want to clear value filters without removing label filters or manual filtering.
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();