[]
An IPivotTable is a member of the IPivotTables collection and is used to summarize and analyze data from a IPivotCache on a worksheet.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"A", 100}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.setName("SalesPivot");
addDataField(IPivotField field,
String caption,
ConsolidationFunction function) voidvoidbooleanbooleanintbooleanbooleanbooleanbooleanbooleanbooleangetDisplayErrorString() is true.booleanbooleangetName()getDisplayNullString() is true.intIPivotCache used by this PivotTable report.IPivotAxis object that represents the entire column axis of the PivotTable report.IPivotAxis object that represents the entire row axis of the PivotTable report.booleanbooleanbooleanbooleanbooleanbooleangetStyle()getTag()pivotValueCell(int rowline,
int columnline) IPivotValueCell at the specified row and column position in the PivotTable data area.booleanrefresh()voidvoidsetAllowMultipleFilters(boolean allowMultipleFilters) voidsetColumnGrand(boolean value) voidsetCompactRowIndent(int value) voidsetDeferLayoutUpdate(boolean value) voidsetDisplayContextTooltips(boolean value) voidsetDisplayErrorString(boolean value) voidsetDisplayFieldCaptions(boolean displayFieldCaptions) voidsetDisplayMemberPropertyTooltips(boolean value) voidsetDisplayNullString(boolean value) voidsetErrorString(String value) getDisplayErrorString() is true.voidsetGrandTotalName(String value) voidsetHasAutoFormat(boolean value) voidsetLayoutRowDefault(LayoutRowType value) IPivotField objects when they are added to the IPivotTable for the first time.voidsetMergeLabels(boolean value) voidvoidsetNullString(String value) getDisplayNullString() is true.voidsetPageFieldOrder(Order value) voidsetPageFieldWrapCount(int value) voidsetRowAxisLayout(LayoutRowType rowLayout) voidsetRowGrand(boolean value) voidsetShowTableStyleColumnHeaders(boolean value) voidsetShowTableStyleColumnStripes(boolean value) voidsetShowTableStyleLastColumn(boolean value) voidsetShowTableStyleRowHeaders(boolean value) voidsetShowTableStyleRowStripes(boolean value) voidsetStyle(ITableStyle style) voidsetTableStyle(String value) voidvoidsubtotalLocation(SubtotalLocationType location) voidupdate()This property indicates whether a grand total is displayed for the column area of the PivotTable report. The default value is true.
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");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
boolean showColumnGrand = pivotTable.getColumnGrand();
true if the PivotTable report shows grand totals for columns; otherwise, false.This property indicates whether a grand total is displayed for the column area of the PivotTable report. The default value is true.
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");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.setColumnGrand(true);
value - Whether the PivotTable report shows grand totals for columns.The returned collection is read-only and contains the fields whose orientation is set to column fields.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Region", "Amount"},
{"Beverages", "East", 120},
{"Beverages", "West", 80},
{"Snacks", "East", 95},
{"Snacks", "West", 110}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
IPivotFields columnFields = pivotTable.getColumnFields();
The returned range covers the cells used for column fields in the current PivotTable layout.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Region", "Amount"},
{"Beverages", "East", 120},
{"Beverages", "West", 80},
{"Snacks", "East", 95},
{"Snacks", "West", 110}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
pivotTable.addDataField(pivotTable.getPivotFields().get("Amount"), "Sum of Amount", ConsolidationFunction.Sum);
IRange range = pivotTable.getColumnRange();
String address = range.getAddress();
This value controls how much each nested pivot item is indented when the PivotTable report uses compact row layout.
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");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.setCompactRowIndent(2);
int indent = pivotTable.getCompactRowIndent();
This value controls how much each nested pivot item is indented when the PivotTable report uses compact row layout.
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");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.setCompactRowIndent(2);
value - The indent increment for pivot items when compact row layout is enabled.The returned range represents the cells between the header area and the insert row.
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");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.addDataField(pivotTable.getPivotFields().get("Amount"), "Sum of Amount", ConsolidationFunction.Sum);
IRange range = pivotTable.getDataBodyRange();
The returned collection is read-only and contains the fields placed in the Values area of the PivotTable.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Fruit", 80},
{"Vegetables", 60}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.addDataField(pivotTable.getPivotFields().get("Amount"), "Sum of Amount", ConsolidationFunction.Sum);
IPivotFields dataFields = pivotTable.getDataFields();
String caption = dataFields.get(0).getName();
When this property is true, layout changes can be accumulated and then applied by calling update().
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Product", "Amount"},
{"Beverages", "Tea", 100},
{"Beverages", "Coffee", 200},
{"Snacks", "Biscuits", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
pivotTable.setDeferLayoutUpdate(true);
boolean deferred = pivotTable.getDeferLayoutUpdate();
When this property is true, layout changes can be accumulated and then applied by calling update().
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Product", "Amount"},
{"Beverages", "Tea", 100},
{"Beverages", "Coffee", 200},
{"Snacks", "Biscuits", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
pivotTable.setDeferLayoutUpdate(true);
value - Whether layout updates for the PivotTable are deferred.This property indicates whether context tooltips are shown for cells in the PivotTable report.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Amount"},
{"A", 100},
{"B", 200},
{"A", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
boolean displayContextTooltips = pivotTable.getDisplayContextTooltips();
true if context tooltips are displayed for PivotTable cells; otherwise, false.This property indicates whether context tooltips are shown for cells in the PivotTable report.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Amount"},
{"A", 100},
{"B", 200},
{"A", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setDisplayContextTooltips(true);
value - Whether tooltips are displayed for PivotTable cells.When this property is true, the PivotTable uses the string specified by getErrorString() for cells that contain errors. The default value is false.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"A", 10},
{"B", 20},
{"A", 15}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.setDisplayErrorString(true);
boolean displayErrorString = pivotTable.getDisplayErrorString();
When this property is true, the PivotTable uses the string specified by getErrorString() for cells that contain errors. The default value is false.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"A", 10},
{"B", 20},
{"A", 15}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.setDisplayErrorString(true);
value - Whether the PivotTable report displays a custom error string in cells that contain errors.When this property is true, tooltips can include member property information for PivotTable items.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"A", 100},
{"B", 200},
{"A", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setDisplayMemberPropertyTooltips(true);
boolean displayMemberPropertyTooltips = pivotTable.getDisplayMemberPropertyTooltips();
When this property is true, tooltips can include member property information for PivotTable items.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"A", 100},
{"B", 200},
{"A", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setDisplayMemberPropertyTooltips(true);
value - Whether member properties are displayed in PivotTable tooltips.When this property is true, the PivotTable uses the string specified by getNullString() for cells that contain null values. The default value is true.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", null},
{"A", 200}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
boolean displayNullString = pivotTable.getDisplayNullString();
true if the PivotTable report displays a custom string in cells that contain null values; otherwise, false.When this property is true, the PivotTable uses the string specified by getNullString() for cells that contain null values. The default value is true.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", null},
{"A", 200}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.setDisplayNullString(true);
value - Whether the PivotTable report displays a custom string in cells that contain null values.getDisplayErrorString() is true. The default value is an empty string ( ""). Use setErrorString(String) to specify the custom error text shown by the PivotTable for error cells.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"A", 10},
{"B", 20},
{"A", 15}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.setDisplayErrorString(true);
pivotTable.setErrorString("Invalid");
String errorString = pivotTable.getErrorString();
getDisplayErrorString() is true.getDisplayErrorString() is true. The default value is an empty string ( ""). Use setErrorString(String) to specify the custom error text shown by the PivotTable for error cells.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"A", 10},
{"B", 20},
{"A", 15}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.setDisplayErrorString(true);
pivotTable.setErrorString("Invalid");
value - The string displayed in cells that contain errors when getDisplayErrorString() is true.The default label is "Grand Total".
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Region", "Sales"},
{"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");
String grandTotalName = pivotTable.getGrandTotalName();
The default label is "Grand Total".
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Region", "Sales"},
{"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");
pivotTable.setGrandTotalName("Sample");
value - The text label displayed in the grand total row heading or grand total column heading of the PivotTable report.This setting determines the initial row layout used for newly added PivotFields, such as compact, outline, or tabular layout.
worksheet.getRange("A1:C4").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 120},
{"West", "Apple", 80},
{"East", "Orange", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.setLayoutRowDefault(LayoutRowType.TabularRow);
LayoutRowType layoutType = pivotTable.getLayoutRowDefault();
IPivotField objects when they are added to the IPivotTable for the first time.This setting applies to newly added PivotFields. To change the layout of existing PivotFields at the same time, use setRowAxisLayout(LayoutRowType).
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 100},
{"East", "Pear", 80},
{"West", "Apple", 120},
{"West", "Pear", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.setLayoutRowDefault(LayoutRowType.TabularRow);
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
value - The default layout row type to apply when a PivotField is added to the PivotTable for the first time.Use this property to determine whether repeated labels in the PivotTable layout are displayed by merging adjacent cells.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 100},
{"East", "Pear", 200},
{"West", "Apple", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.setMergeLabels(true);
boolean mergeLabels = pivotTable.getMergeLabels();
true if the specified PivotTable report uses merged cells for outer-row items, column items, subtotals, and grand total labels; otherwise, false.Use this property to set whether repeated labels in the PivotTable layout are displayed by merging adjacent cells.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 100},
{"East", "Pear", 200},
{"West", "Apple", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.setMergeLabels(true);
value - Whether the specified PivotTable report uses merged cells for outer-row items, column items, subtotals, and grand total labels.The name identifies the PivotTable on the worksheet and can be used to reference the PivotTable programmatically.
worksheet.getRange("A1:C4").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 120},
{"West", "Apple", 80},
{"East", "Orange", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
String name = pivotTable.getName();
The name identifies the PivotTable on the worksheet and can be used to reference the PivotTable programmatically.
worksheet.getRange("A1:C4").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 120},
{"West", "Apple", 80},
{"East", "Orange", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.setName("Sample");
value - The PivotTable name.getDisplayNullString() is true. The default value is an empty string ( "").
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", null},
{"A", 200}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setDisplayNullString(true);
pivotTable.setNullString("(blank)");
String nullString = pivotTable.getNullString();
getDisplayNullString() is true.getDisplayNullString() is true. The default value is an empty string ( "").
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", null},
{"A", 200}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setDisplayNullString(true);
pivotTable.setNullString("(blank)");
value - The string displayed in PivotTable cells that contain null values when getDisplayNullString() is true.The returned value is one of the Order constants: Order.DownThenOver or Order.OverThenDown. The default value is Order.DownThenOver.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 100},
{"East", "Pear", 80},
{"West", "Apple", 90},
{"West", "Pear", 70}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.PageField);
pivotTable.setPageFieldOrder(Order.OverThenDown);
Order order = pivotTable.getPageFieldOrder();
Use Order.DownThenOver to place page fields down each column before moving to the next column, or Order.OverThenDown to place page fields across each row before moving to the next row. The default value is Order.DownThenOver.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 100},
{"East", "Pear", 80},
{"West", "Apple", 90},
{"West", "Pear", 70}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.PageField);
pivotTable.setPageFieldOrder(Order.OverThenDown);
value - The page field layout order. Use Order.DownThenOver or Order.OverThenDown; if null is specified, it is treated as Order.DownThenOver.The returned collection is read-only and contains the fields whose orientation is set to the page area of the PivotTable report.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 100},
{"East", "Pear", 80},
{"West", "Apple", 90},
{"West", "Pear", 70}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.PageField);
IPivotFields pageFields = pivotTable.getPageFields();
This value determines how page fields are wrapped in the report filter area when the PivotTable contains multiple page fields. Use setPageFieldWrapCount(int) to change the layout.
worksheet.getRange("A1:D5").setValue(new Object[][] {
{"Region", "Product", "Quarter", "Amount"},
{"East", "Apple", "Q1", 120},
{"East", "Pear", "Q2", 95},
{"West", "Apple", "Q1", 80},
{"West", "Pear", "Q2", 110}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:D5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("F1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.PageField);
pivotTable.getPivotFields().get("Quarter").setOrientation(PivotFieldOrientation.PageField);
pivotTable.setPageFieldWrapCount(1);
int wrapCount = pivotTable.getPageFieldWrapCount();
This value determines how page fields are wrapped in the report filter area when the PivotTable contains multiple page fields. Use setPageFieldWrapCount(int) to change the layout.
worksheet.getRange("A1:D5").setValue(new Object[][] {
{"Region", "Product", "Quarter", "Amount"},
{"East", "Apple", "Q1", 120},
{"East", "Pear", "Q2", 95},
{"West", "Apple", "Q1", 80},
{"West", "Pear", "Q2", 110}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:D5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("F1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.PageField);
pivotTable.getPivotFields().get("Quarter").setOrientation(PivotFieldOrientation.PageField);
pivotTable.setPageFieldWrapCount(1);
value - The number of page fields displayed in each column or row of the PivotTable report.The page area is the report filter area that displays fields whose orientation is set to page fields. This method returns null if the PivotTable does not currently have a page area.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 100},
{"East", "Pear", 80},
{"West", "Apple", 90},
{"West", "Pear", 70}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.PageField);
IRange pageRange = pivotTable.getPageRange();
IPivotAxis object that represents the entire column axis of the PivotTable report.Use this axis to work with the column-side structure of a PivotTable, such as the pivot lines displayed across the top of the report.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Region", "Amount"},
{"Beverages", "East", 120},
{"Beverages", "West", 80},
{"Snacks", "East", 95},
{"Snacks", "West", 110}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
IPivotAxis columnAxis = pivotTable.getPivotColumnAxis();
IPivotLines lines = columnAxis.getPivotLines();
IPivotAxis object that represents the entire column axis of the PivotTable report.IPivotAxis object that represents the entire row axis of the PivotTable report.Use this axis to work with the row-side structure of a PivotTable, such as the pivot lines displayed down the left side of the report.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Region", "Amount"},
{"Beverages", "East", 120},
{"Beverages", "West", 80},
{"Snacks", "East", 95},
{"Snacks", "West", 110}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
IPivotAxis rowAxis = pivotTable.getPivotRowAxis();
IPivotLines lines = rowAxis.getPivotLines();
IPivotAxis object that represents the entire row axis of the PivotTable report.The returned IPivotFields collection is read-only and contains the fields whose orientation is set to row fields.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 120},
{"East", "Pear", 80},
{"West", "Apple", 95},
{"West", "Pear", 110}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
IPivotFields rowFields = pivotTable.getRowFields();
String firstFieldName = rowFields.get(0).getName();
IPivotFields.Use this method to determine whether the PivotTable displays a grand total row for the row fields.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Region", "Amount"},
{"East", 120},
{"West", 150},
{"East", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
boolean showRowGrand = pivotTable.getRowGrand();
true if the PivotTable report shows grand totals for rows; otherwise, false.Use this method to set whether the PivotTable displays a grand total row for the row fields.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Region", "Amount"},
{"East", 120},
{"West", 150},
{"East", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.setRowGrand(value);
value - Whether the PivotTable report shows grand totals for rows.The returned range represents the cells used by row fields and row items in the current PivotTable layout.
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");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
IRange rowRange = pivotTable.getRowRange();
This property indicates whether the PivotTable shows its column header area using the current table style settings.
worksheet.getRange("A1:D5").setValue(new Object[][] {
{"Category", "Product", "Amount", "Region"},
{"Beverages", "Tea", 100, "East"},
{"Beverages", "Coffee", 200, "West"},
{"Snacks", "Chips", 150, "East"},
{"Snacks", "Nuts", 120, "West"}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:D5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("F1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
boolean showColumnHeaders = pivotTable.getShowTableStyleColumnHeaders();
This property indicates whether the PivotTable shows its column header area using the current table style settings.
worksheet.getRange("A1:D5").setValue(new Object[][] {
{"Category", "Product", "Amount", "Region"},
{"Beverages", "Tea", 100, "East"},
{"Beverages", "Coffee", 200, "West"},
{"Snacks", "Chips", 150, "East"},
{"Snacks", "Nuts", 120, "West"}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:D5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("F1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.ColumnField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.setShowTableStyleColumnHeaders(value);
value - Whether column headers are displayed in the PivotTable.When this property is true, even columns are formatted differently from odd columns to make the PivotTable easier to read.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Drink", 200},
{"Fruit", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setShowTableStyleColumnStripes(true);
boolean showColumnStripes = pivotTable.getShowTableStyleColumnStripes();
When this property is true, even columns are formatted differently from odd columns to make the PivotTable easier to read.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Drink", 200},
{"Fruit", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setShowTableStyleColumnStripes(true);
value - Whether banded columns are displayed in the PivotTable style.This property indicates whether the PivotTable style is applied to the last column of the PivotTable report.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Drink", 200},
{"Fruit", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.setShowTableStyleLastColumn(true);
boolean showLastColumnStyle = pivotTable.getShowTableStyleLastColumn();
This property indicates whether the PivotTable style is applied to the last column of the PivotTable report.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Drink", 200},
{"Fruit", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.setShowTableStyleLastColumn(true);
value - Whether the last column style is displayed in the PivotTable.Use this method to determine whether the current PivotTable style shows row header formatting.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Drink", 200},
{"Fruit", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setShowTableStyleRowHeaders(true);
boolean showRowHeaders = pivotTable.getShowTableStyleRowHeaders();
Use this method to set whether the current PivotTable style shows row header formatting.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Drink", 200},
{"Fruit", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setShowTableStyleRowHeaders(true);
value - Whether row headers are displayed in the PivotTable style.When this property is true, the PivotTable style applies alternating row formatting to improve readability.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Beverages", 120},
{"Snacks", 95},
{"Beverages", 80}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
boolean showRowStripes = pivotTable.getShowTableStyleRowStripes();
When this property is true, the PivotTable style applies alternating row formatting to improve readability.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Beverages", 120},
{"Snacks", 95},
{"Beverages", 80}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.setShowTableStyleRowStripes(value);
value - Whether banded rows are displayed in the PivotTable so that even rows are formatted differently from odd rows.Use this method to access the rendered PivotTable area without including any page field region that is displayed separately from the main report.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Fruit", 200},
{"Vegetable", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
IRange range = pivotTable.getTableRange1();
String address = range.toString();
Use this method to retrieve the full displayed PivotTable area, including filter areas, rather than only the main report body.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Beverages", 120},
{"Beverages", 80},
{"Snacks", 50}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D2"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
IRange range = pivotTable.getTableRange2();
The default value is a null string, which indicates that no style is applied.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Beverages", 120},
{"Beverages", 80},
{"Snacks", 95}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setTableStyle("PivotStyleMedium9");
String styleName = pivotTable.getTableStyle();
The default value is a null string, which indicates that no style is applied.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Beverages", 120},
{"Beverages", 80},
{"Snacks", 95}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setTableStyle("PivotStyleMedium9");
value - The style used in the body of the PivotTable report.Use this property to retrieve custom text metadata associated with the PivotTable report. To store a value, use setTag(String).
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Region", "Amount"},
{"East", 120},
{"West", 80},
{"East", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setTag("Monthly sales summary");
String tag = pivotTable.getTag();
The value is saved with the PivotTable report.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Region", "Amount"},
{"East", 120},
{"West", 80},
{"East", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setTag("Monthly sales summary");
value - The custom text metadata to associate with the PivotTable report.Use this method to add a source field to the values area and specify the summary function used for that data field.
Object[][] sourceData = {
{"Region", "Product", "Amount"},
{"East", "Apple", 120},
{"West", "Apple", 80},
{"East", "Orange", 90}
};
worksheet.getRange("A1:C4").setValue(sourceData);
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.addDataField(pivotTable.getPivotFields().get("Amount"), "Sum of Amount", ConsolidationFunction.Sum);
field - The unique field on the server. If the source data is OLAP, this field is a cube field; otherwise, it is a PivotTable field.caption - The label used in the PivotTable report to identify the added data field.function - The function performed in the added data field.IPivotField.Use the returned ICalculatedFields collection to access or add calculated fields for the current PivotTable.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Product", "Amount"},
{"Apple", 120},
{"Orange", 90},
{"Apple", 80}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
ICalculatedFields calculatedFields = pivotTable.getCalculatedFields();
calculatedFields.add("DoubleAmount", "=Amount*2");
ICalculatedFields.This method removes filters in the pivot table's filter collection, clears manual filtering, and resets all pivot fields in the Report Filter area to their default item.
Object[][] sourceData = {
{"Product", "Country", "Amount"},
{"Apple", "Canada", 120},
{"Apple", "France", 150},
{"Banana", "Canada", 90}
};
worksheet.getRange("A1:C4").setValue(sourceData);
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
IPivotField fieldProduct = pivotTable.getPivotFields().get("Product");
fieldProduct.setOrientation(PivotFieldOrientation.RowField);
IPivotField fieldAmount = pivotTable.getPivotFields().get("Amount");
fieldAmount.setOrientation(PivotFieldOrientation.DataField);
fieldProduct.getPivotFilters().add(PivotFilterType.CaptionContains, "pp");
pivotTable.clearAllFilters();
Clearing a PivotTable removes all fields and deletes any filtering and sorting applied to the report. This method resets the PivotTable to the state it had immediately after creation, before any fields were added.
Object[][] sourceData = {
{"Product", "Region", "Amount"},
{"Apple", "East", 120},
{"Pear", "West", 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"), "PivotTable1");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
pivotTable.addDataField(pivotTable.getPivotFields().get("Amount"), "Sum of Amount", ConsolidationFunction.Sum);
pivotTable.clearTable();
IPivotCache used by this PivotTable report.The returned cache represents the source data cache associated with the PivotTable.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Product", "Sales"},
{"Apple", 100},
{"Orange", 200},
{"Pear", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
IPivotCache cache = pivotTable.getPivotCache();
IPivotCache used by this PivotTable report.The returned IPivotFields collection includes both visible and hidden fields from the PivotTable data source. You can use this collection to access individual fields and configure how they are used in the report layout.
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");
IPivotFields pivotFields = pivotTable.getPivotFields();
pivotFields.get("Category").setOrientation(PivotFieldOrientation.RowField);
IPivotFields.IPivotValueCell at the specified row and column position in the PivotTable data area.Use this method to access a calculated value cell in a PivotTable report and then inspect its value or related IPivotCell information.
worksheet.getRange("A1:B3").setValue(new Object[][] {
{"Region", "Amount"},
{"East", 100},
{"West", 200}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"));
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
IPivotValueCell valueCell = pivotTable.pivotValueCell(0, 0);
Object value = valueCell.getValue();
rowline - The row position in the data area.columnline - The column position in the data area.IPivotValueCell at the specified position.Use this method after the source data has changed and you need the PivotTable to reflect the latest data.
This method performs the following actions:
IPivotCache.IPivotFields with the refreshed cache.If only the PivotTable layout or display settings have changed and the source data has not changed, use update() instead.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Product", "Amount"},
{"Apple", 100},
{"Apple", 200},
{"Orange", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "PivotTable1");
pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
worksheet.getRange("B2").setValue(120);
boolean refreshed = pivotTable.refresh();
true if the refresh succeeds.IllegalStateException - if the source sheet of the PivotTable cannot be found.This setting is applied to all existing pivot fields in the pivot table.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Product", "Amount"},
{"Beverages", "Tea", 100},
{"Beverages", "Coffee", 200},
{"Snacks", "Chips", 150},
{"Snacks", "Nuts", 120}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
pivotTable.repeatAllLabels(PivotFieldRepeatLabels.RepeatLabels);
repeat - Specifies whether to repeat item labels for all pivot fields in the pivot table.Use this method to apply a single LayoutRowType to the current row fields at once. To set the default layout for PivotFields added later, use setLayoutRowDefault(LayoutRowType).
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Region", "Product", "Amount"},
{"East", "Apple", 120},
{"West", "Apple", 80},
{"East", "Orange", 90},
{"West", "Orange", 110}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.getPivotFields().get("Region").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.setRowAxisLayout(LayoutRowType.TabularRow);
rowLayout - The row axis layout type to apply to all existing PivotFields.Changing the subtotal location has an immediate visual effect only for fields in outline form, but the setting is also applied to fields in tabular form.
If the row axis layout is LayoutRowType.TabularRow, the location must be SubtotalLocationType.Bottom.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Beverages", 100},
{"Snacks", 200},
{"Beverages", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"));
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.subtotalLocation(SubtotalLocationType.Bottom);
location - The subtotal location to apply to all existing pivot fields.IllegalArgumentException - if the row axis layout is LayoutRowType.TabularRow and location is not SubtotalLocationType.Bottom.A common use case is to enable setDeferLayoutUpdate(boolean), make multiple layout changes, and then call this method once to apply them.
This method does not refresh the PivotCache from the source data. If the source data has changed and the PivotCache must be refreshed first, call refresh() instead.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Product", "Amount"},
{"Beverages", "Tea", 100},
{"Beverages", "Coffee", 200},
{"Snacks", "Biscuits", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "PivotTable1");
pivotTable.setDeferLayoutUpdate(true);
pivotTable.getPivotFields().get("Category").setOrientation(PivotFieldOrientation.RowField);
pivotTable.getPivotFields().get("Amount").setOrientation(PivotFieldOrientation.DataField);
pivotTable.update();
This method returns the current ITableStyle associated with the pivot table. If no style has been applied, this method returns null.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Amount"},
{"A", 100},
{"B", 200},
{"A", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setStyle(workbook.getTableStyles().get("PivotStyleMedium3"));
ITableStyle style = pivotTable.getStyle();
String styleName = style.getName();
This method Sets the current ITableStyle associated with the pivot table. If no style has been applied, this method Sets null.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Amount"},
{"A", 100},
{"B", 200},
{"A", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("D1"), "SalesPivot");
pivotTable.setStyle(workbook.getTableStyles().get("PivotStyleMedium3"));
String styleName = style.getName();
style - The style applied to the pivot table.Use this method to access the IPivotFormulas collection that contains the custom formulas defined for the PivotTable, such as formulas created by calculated items.
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);
pivotTable.getPivotFields().get("Product").getCalculatedItems().add("TotalFruit", "=Product[Apple] + Product[Banana]");
IPivotFormulas formulas = pivotTable.getPivotFormulas();
IPivotFormula formula = formulas.get(0);
Use this property to determine whether the pivot table allows a single pivot field to keep more than one filter condition simultaneously.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Product", "Amount"},
{"Fruit", "Apple", 120},
{"Fruit", "Banana", 90},
{"Drink", "Tea", 60},
{"Drink", "Coffee", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.setAllowMultipleFilters(true);
boolean allowMultipleFilters = pivotTable.getAllowMultipleFilters();
Use this property to set whether the pivot table allows a single pivot field to keep more than one filter condition simultaneously.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Category", "Product", "Amount"},
{"Fruit", "Apple", 120},
{"Fruit", "Banana", 90},
{"Drink", "Tea", 60},
{"Drink", "Coffee", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C5"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.setAllowMultipleFilters(true);
allowMultipleFilters - Whether pivot fields in the pivot table can have multiple filters applied at the same time.The default value is true.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Product", "Amount"},
{"Apple", 100},
{"Orange", 200},
{"Apple", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
boolean hasAutoFormat = pivotTable.getHasAutoFormat();
true if the PivotTable report automatically fits column widths when refreshed; otherwise, false.The default value is true.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Product", "Amount"},
{"Apple", 100},
{"Orange", 200},
{"Apple", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
IPivotTable pivotTable = worksheet.getPivotTables().add(pivotCache, worksheet.getRange("E1"), "SalesPivot");
pivotTable.setHasAutoFormat(true);
value - Whether the PivotTable report automatically fits column widths when it is refreshed.
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.setDisplayFieldCaptions(false);
boolean displayFieldCaptions = pivotTable.getDisplayFieldCaptions();
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.setDisplayFieldCaptions(false);
displayFieldCaptions - true to display filter buttons and field captions; otherwise, false.