Class PivotTableView
Sheet.pivotTable(int) or Sheet.pivotTable(String): getters
read the engine's deep pivot model, mutators apply immediately.
Field placement follows the Excel model (ECMA-376 Part 1 §18.10): source
columns go to the row / column / filter (page) axes or, with an
AggregateFunction, to the values area. The same source column may
appear several times in the values area ("Sum of Sales" + "Count of
Sales"). refresh() runs the engine's pivot cube over the current
source range and materializes the computed output into the sheet at the
pivot anchor — like Excel's Refresh, the previous output region is
overwritten.
Any mutation invalidates the byte-preserved pivotTableN.xml
carried from import: the next save regenerates the pivot parts from the
model (and marks the cache refreshOnLoad), so the edit is what
lands on disk — never the stale imported bytes.
Filtering: manual item filters (setItemFilter(java.lang.String, java.lang.String...)), report
(page) filters (setPageFilter(java.lang.String, java.lang.String)), caption filters
(setLabelFilter(java.lang.String, io.keikai.axyra.sheets.PivotLabelFilterType, java.lang.String)), and value filters (setValueFilter(java.lang.String, int, io.keikai.axyra.sheets.PivotValueFilterType, double));
items sort by label or by a data field's aggregate
(sortField(java.lang.String, boolean)/sortFieldByValue(java.lang.String, boolean, int)). Values transform via
setShowDataAs(int, io.keikai.axyra.sheets.PivotShowDataAsType) and virtual columns come from
addCalculatedField(java.lang.String, java.lang.String).
Calculated items (addCalculatedItem(java.lang.String, java.lang.String, java.lang.String)), multi-level date and
numeric grouping (groupFieldByDate(java.lang.String, io.keikai.axyra.sheets.PivotDateGroupBy)/groupFieldNumeric(java.lang.String, double, double, double)),
Top-N filters (setTopNFilter(java.lang.String, int, int, boolean)), and named styles
(setStyle(io.keikai.axyra.sheets.PivotStyle)) complete the surface. See docs/java-api/08.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddCalculatedField(String name, String formula) Defines a calculated field — a virtual source column whose value isformulaevaluated over the sums of the referenced source fields within each pivot bucket (Excel's calculated-field semantics; ECMA-376 Part 1 §18.10.1.13cacheField@formula).voidaddCalculatedItem(String field, String name, String formula) Defines a calculated item on the row/column fieldfield— a virtual item whose per-cell value isformulaevaluated over the field's other items (ECMA-376 Part 1 §18.10.1.9; e.g.voidaddColumnField(String sourceField) AddssourceFieldto the column axis (nested innermost).voidaddDataField(String sourceField, AggregateFunction function) AddssourceFieldto the values area with the default caption.voidaddDataField(String sourceField, AggregateFunction function, String customName) AddssourceFieldto the values area.voidaddFilterField(String sourceField) AddssourceFieldas a report filter (ECMA-376 page field).voidaddPageField(String sourceField) Alias ofaddFilterField(java.lang.String)using the OOXML "page field" name.voidaddRowField(String sourceField) AddssourceFieldto the row axis (nested innermost).The calculated-field definitions, in definition order.The calculated-item definitions, in definition order.booleanclearFieldSort(String field) Restores manual/source item order forfield.booleanclearLabelFilter(String field) Clears the caption (label) filter offield.booleanclearShowDataAs(int position) Restores the raw aggregate for theposition-th values field.booleanclearTopNFilter(String field) Clears the Top-N filter offield.booleanclearValueFilter(String field) Clears the value filter offield.The column-axis fields, in nesting order.The values-area fields, in order.fieldGroup(String field) The grouping offield, or null when ungrouped.The declared sort offield, or null for manual/source order.The report-filter (page) fields.The grand-total caption override, or null (locale default).booleanWhether the grand-total column (right) is shown.booleanWhether the grand-total row (bottom) is shown.booleangroupFieldByDate(String field, PivotDateGroupBy by) Groups the row/column fieldfieldby a date component (ECMA-376 Part 1 §18.10.1.81rangePr@groupBy): onrefresh()the field's items become the component labels in calendar order (MONTHS-> "Jan".."Dec",QUARTERS-> "Qtr1".."Qtr4", …).booleangroupFieldByDate(String field, PivotDateGroupBy... components) Multi-level date grouping — Excel's Years/Quarters/Months expansion:components[0]becomes the outermost level.booleangroupFieldNumeric(String field, double start, double end, double interval) Groups the row/column fieldfieldinto numeric bins ofintervalover[start, end]— Excel's label shapes ("0-9", last bin"90-100", outliers"<0"/">100").intindex()This pivot table's index on its sheet.String[]itemFilter(String field) The currently visible items offield's manual filter: the distinct source-column items minus the hidden ones.labelFilter(String field) The caption (label) filter offield, or null when unfiltered.layout()The report layout (compact / outline / tabular).location()The output anchor (e.g.voidmoveColumnField(int from, int to) Reorders column fields: moves positionfromtoto.voidmoveDataField(int from, int to) Reorders data fields: moves positionfromtoto.voidmoveRowField(int from, int to) Reorders row fields: moves positionfromtoto.name()The pivot table name.pageFilter(String field) The selected item of the report-filter (page) fieldfield, or null for "(All)" — also null when the field is unknown or not a filter field.intrefresh()Re-reads the source range, runs the pivot cube engine (aggregation + layout), and materializes the computed output into the sheet at the pivot anchor — row labels, column headers, values, and grand totals become ordinary cells (like Excel's Refresh).The user name stamped on the pivot cache the last time it was refreshed (therefreshedByattribute ofpivotCacheDefinition, ECMA-376 Part 1 §18.10.1.67), ornullwhen the source file carries none — as for a pivot table built through this API.voidreload()Re-read the pivot state from the engine.voidremoveCalculatedField(String name) Removes the calculated fieldnametogether with every values-area placement referencing it.voidremoveCalculatedItem(String field, String name) Removes the calculated itemnamefromfield.voidremoveColumnField(int position) Removes theposition-th column field.voidremoveDataField(int position) Removes theposition-th data (values) field.voidremoveFilterField(int position) Removes theposition-th report-filter field.voidremoveRowField(int position) Removes theposition-th row field (0-based nesting order).The row-axis fields, in nesting order.voidsetColumnFieldCaption(int position, String caption) Renames theposition-th column field; seesetRowFieldCaption(int, java.lang.String).voidsetColumnFieldSubtotals(int position, boolean show) Toggles subtotals for theposition-th column field.voidsetFilterFieldCaption(int position, String caption) Renames theposition-th report-filter field; seesetRowFieldCaption(int, java.lang.String).voidsetGrandTotalCaption(String caption) Sets the grand-total caption (ECMA-376 Part 1 §18.10.1.46); passnullto restore the locale default ("Grand Total").voidsetGrandTotals(boolean grandTotalRow, boolean grandTotalColumn) Toggles the grand-total row (bottom) and grand-total column (right).booleansetItemFilter(String field, String... visibleItems) Restrictsfield's manual item filter tovisibleItems— Excel's filter dropdown with only those entries checked (ECMA-376 Part 1 §18.10.1.45item@h).booleansetLabelFilter(String field, PivotLabelFilterType type, String value) Sets the caption (label) filter of the row/column fieldfield— Excel's "Label Filters" menu (ECMA-376 Part 1 §18.10.1.32).voidsetLayout(PivotLayout layout) Sets the report layout (ECMA-376 Part 1 §18.10.1.73; BOR-PV-001).booleansetPageFilter(String field, String item) Selects a single item on the report-filter (page) fieldfield— Excel's single-select page filter dropdown (ECMA-376 Part 1 §18.10.1.62pageField@item).voidsetRowFieldCaption(int position, String caption) Renames theposition-th row field for display (ECMA-376 Part 1 §18.10.1.69pivotField@name— Excel writes this attribute when a placed field is renamed in the pivot UI); passnullto restore the source column name.voidsetRowFieldSubtotals(int position, boolean show) Toggles subtotals for theposition-th row field.booleansetShowDataAs(int position, PivotShowDataAsType type) Sets the Show-Values-As mode of theposition-th values-area field for the base-less modes (percent of total/row/column, running total, ranks, index).booleansetShowDataAs(int position, PivotShowDataAsType type, String baseField, String baseItem) Sets the Show-Values-As mode with base references:baseFieldnames a row/column-placed field,baseItemone of its item labels.booleansetStyle(PivotStyle style) Applies a named pivot style + banding flags (ECMA-376 Part 1 §18.10.1.88pivotTableStyleInfo); Excel renders the bands on open.booleanAppliesnamewith Excel's Design-tab default flags.booleansetTopNFilter(String field, int dataField, int count, boolean bottom) Keeps only the top (or bottom)countitems of the row/column fieldfield, ranked by their aggregate of thedataField-th values-area entry — Excel's "Top 10" value filter.booleansetTopPercentFilter(String field, int dataField, double percent, boolean bottom) Percent mode: keeps the top (or bottom) items whose aggregates accumulate topercentof the field's total.booleansetValueFilter(String field, int dataField, PivotValueFilterType type, double value) Sets a single-threshold value filter on the row/column fieldfield: each item's aggregate of thedataField-th values-area entry is compared withtype; failing items (and items with no numeric aggregate) are hidden on the nextrefresh().booleansetValueFilterBetween(String field, int dataField, double low, double high) PivotValueFilterType.BETWEENform:low <= aggregate <= high.showDataAs(int position) The Show-Values-As state of theposition-th values-area field, or null when the position is out of range.booleanSorts the row/column fieldfieldby item label (ECMA-376 Part 1 §18.10.1.69sortType; BOR-PVE-014 NC1).booleansortFieldByValue(String field, boolean ascending, int dataField) Sorts the row/column fieldfieldby the aggregate of thedataField-th values-area entry (§18.10.1.72autoSortScope; BOR-PVE-014 R1).The source column names available for field placement.The source data reference (e.g.style()The named pivot style, or null when none is applied.topNFilter(String field) The Top-N filter offield, or null when unfiltered.booleanungroupField(String field) Removesfield's grouping (items revert to the raw values).valueFilter(String field) The value filter offield, or null when unfiltered.
-
Method Details
-
reload
public void reload()Re-read the pivot state from the engine. -
index
public int index()This pivot table's index on its sheet. -
name
The pivot table name. -
location
The output anchor (e.g."H1"). -
sourceRef
The source data reference (e.g."Sheet1!A1:D10"). -
refreshedBy
The user name stamped on the pivot cache the last time it was refreshed (therefreshedByattribute ofpivotCacheDefinition, ECMA-376 Part 1 §18.10.1.67), ornullwhen the source file carries none — as for a pivot table built through this API. -
sourceFields
The source column names available for field placement. -
addRowField
AddssourceFieldto the row axis (nested innermost). -
addColumnField
AddssourceFieldto the column axis (nested innermost). -
addFilterField
AddssourceFieldas a report filter (ECMA-376 page field). -
addPageField
Alias ofaddFilterField(java.lang.String)using the OOXML "page field" name. -
addDataField
AddssourceFieldto the values area with the default caption. -
addDataField
AddssourceFieldto the values area.customNameoverrides the "Sum of Sales"-style default caption (ECMA-376 Part 1 §18.10.1.18dataField@name); passnullto keep the default. -
removeRowField
public void removeRowField(int position) Removes theposition-th row field (0-based nesting order). -
removeColumnField
public void removeColumnField(int position) Removes theposition-th column field. -
removeFilterField
public void removeFilterField(int position) Removes theposition-th report-filter field. -
removeDataField
public void removeDataField(int position) Removes theposition-th data (values) field. -
moveRowField
public void moveRowField(int from, int to) Reorders row fields: moves positionfromtoto. -
moveColumnField
public void moveColumnField(int from, int to) Reorders column fields: moves positionfromtoto. -
moveDataField
public void moveDataField(int from, int to) Reorders data fields: moves positionfromtoto. -
rowFields
The row-axis fields, in nesting order. -
columnFields
The column-axis fields, in nesting order. -
filterFields
The report-filter (page) fields. -
dataFields
The values-area fields, in order. -
layout
The report layout (compact / outline / tabular). -
setLayout
Sets the report layout (ECMA-376 Part 1 §18.10.1.73; BOR-PV-001). -
grandTotalRow
public boolean grandTotalRow()Whether the grand-total row (bottom) is shown. -
grandTotalColumn
public boolean grandTotalColumn()Whether the grand-total column (right) is shown. -
setGrandTotals
public void setGrandTotals(boolean grandTotalRow, boolean grandTotalColumn) Toggles the grand-total row (bottom) and grand-total column (right). OOXML note: the bottom row iscolGrandTotalsand the right column isrowGrandTotals(ECMA-376 Part 1 §18.10.1.15 / §18.10.1.73 — the attribute names are counter-intuitive). -
grandTotalCaption
The grand-total caption override, or null (locale default). -
setGrandTotalCaption
Sets the grand-total caption (ECMA-376 Part 1 §18.10.1.46); passnullto restore the locale default ("Grand Total"). -
setRowFieldSubtotals
public void setRowFieldSubtotals(int position, boolean show) Toggles subtotals for theposition-th row field. -
setColumnFieldSubtotals
public void setColumnFieldSubtotals(int position, boolean show) Toggles subtotals for theposition-th column field. -
setRowFieldCaption
Renames theposition-th row field for display (ECMA-376 Part 1 §18.10.1.69pivotField@name— Excel writes this attribute when a placed field is renamed in the pivot UI); passnullto restore the source column name. -
setColumnFieldCaption
Renames theposition-th column field; seesetRowFieldCaption(int, java.lang.String). -
setFilterFieldCaption
Renames theposition-th report-filter field; seesetRowFieldCaption(int, java.lang.String). -
setTopNFilter
Keeps only the top (or bottom)countitems of the row/column fieldfield, ranked by their aggregate of thedataField-th values-area entry — Excel's "Top 10" value filter. AND-combines with the other filters on the nextrefresh(); ties keep source order.- Returns:
- whether the field exists on the row or column axis and the parameters are valid
-
setTopPercentFilter
Percent mode: keeps the top (or bottom) items whose aggregates accumulate topercentof the field's total. -
clearTopNFilter
Clears the Top-N filter offield. -
topNFilter
The Top-N filter offield, or null when unfiltered. -
setStyle
Applies a named pivot style + banding flags (ECMA-376 Part 1 §18.10.1.88pivotTableStyleInfo); Excel renders the bands on open. Passnullto clear.- Returns:
- whether the pivot exists (and the name is non-empty when set)
-
setStyle
Appliesnamewith Excel's Design-tab default flags. -
style
The named pivot style, or null when none is applied. -
groupFieldByDate
Groups the row/column fieldfieldby a date component (ECMA-376 Part 1 §18.10.1.81rangePr@groupBy): onrefresh()the field's items become the component labels in calendar order (MONTHS-> "Jan".."Dec",QUARTERS-> "Qtr1".."Qtr4", …). Source values must be date serials; text values keep their own label after the buckets.- Returns:
- whether the field exists on the row or column axis
-
groupFieldByDate
Multi-level date grouping — Excel's Years/Quarters/Months expansion:components[0]becomes the outermost level. The expansion shows up as additional row/column levels onrefresh(); re-grouping replaces a previous expansion,ungroupField(java.lang.String)collapses it.- Returns:
- whether the field exists on the row or column axis and the components are non-empty and distinct
-
groupFieldNumeric
Groups the row/column fieldfieldinto numeric bins ofintervalover[start, end]— Excel's label shapes ("0-9", last bin"90-100", outliers"<0"/">100").- Returns:
- whether the field exists on the row or column axis and the
parameters are valid (
interval > 0,end > start)
-
ungroupField
Removesfield's grouping (items revert to the raw values). -
fieldGroup
The grouping offield, or null when ungrouped. -
setShowDataAs
Sets the Show-Values-As mode of theposition-th values-area field for the base-less modes (percent of total/row/column, running total, ranks, index). Applied post-aggregation onrefresh(); percent modes produce fractions (Excel adds the % number format on top).PivotShowDataAsType.NORMALrestores the raw aggregate.- Returns:
- whether
positionis a values-area field
-
setShowDataAs
public boolean setShowDataAs(int position, PivotShowDataAsType type, String baseField, String baseItem) Sets the Show-Values-As mode with base references:baseFieldnames a row/column-placed field,baseItemone of its item labels. Both are required forPivotShowDataAsType.DIFFERENCE_FROMandPivotShowDataAsType.PERCENT_DIFFERENCE_FROM;baseFieldalone forPivotShowDataAsType.PERCENT_OF_PARENT(and it scopesPivotShowDataAsType.RUNNING_TOTAL/ the rank modes).- Returns:
- whether the position and the base references resolve
-
clearShowDataAs
public boolean clearShowDataAs(int position) Restores the raw aggregate for theposition-th values field. -
showDataAs
The Show-Values-As state of theposition-th values-area field, or null when the position is out of range. -
addCalculatedField
Defines a calculated field — a virtual source column whose value isformulaevaluated over the sums of the referenced source fields within each pivot bucket (Excel's calculated-field semantics; ECMA-376 Part 1 §18.10.1.13cacheField@formula). The formula language is arithmetic over source column names:"=Sales*0.1","=Revenue/Units", quoted names ("='Unit Price'*Units") for columns with spaces; the leading=is optional. The definition alone adds no output — place it withaddDataField(String, AggregateFunction)usingname, thenrefresh().Grand totals re-evaluate the formula over the grand sums (they are NOT the sum of the per-row calculated values). A calculated field can only be placed in the values area, and may not reference itself or another calculated field.
- Throws:
AxyraException- when the name clashes with a source column or existing calculated field, or the formula does not parse / references unknown fields
-
removeCalculatedField
Removes the calculated fieldnametogether with every values-area placement referencing it.- Throws:
AxyraException- when no calculated field with that name exists
-
addCalculatedItem
Defines a calculated item on the row/column fieldfield— a virtual item whose per-cell value isformulaevaluated over the field's other items (ECMA-376 Part 1 §18.10.1.9; e.g.addCalculatedItem("Region", "EastWest", "=East+West")). Duplicate references ("=East+East") double the value; the item appears after the source items and IS included in grand totals. Takes effect on the nextrefresh().- Throws:
AxyraException- when the field is not on the row/column axis, the name clashes with a source item or existing calculated item, or the formula does not parse / references unknown items
-
removeCalculatedItem
Removes the calculated itemnamefromfield.- Throws:
AxyraException- when no such calculated item exists
-
calculatedItems
The calculated-item definitions, in definition order. -
calculatedFields
The calculated-field definitions, in definition order. -
setItemFilter
Restrictsfield's manual item filter tovisibleItems— Excel's filter dropdown with only those entries checked (ECMA-376 Part 1 §18.10.1.45item@h). Passing no items clears the filter (every item visible); values not present in the source column are ignored. The field must be placed on an axis (row / column / filter). Takes effect on the nextrefresh().- Returns:
- whether the field exists and is placed on an axis
-
itemFilter
The currently visible items offield's manual filter: the distinct source-column items minus the hidden ones. An unfiltered field returns every item — a filter that hides nothing is the same as no filter. Returns null when the field is unknown or not placed on an axis. -
setPageFilter
Selects a single item on the report-filter (page) fieldfield— Excel's single-select page filter dropdown (ECMA-376 Part 1 §18.10.1.62pageField@item). Passnullto restore "(All)". Takes effect on the nextrefresh().- Returns:
- whether the field exists in the filter (page) area
-
pageFilter
The selected item of the report-filter (page) fieldfield, or null for "(All)" — also null when the field is unknown or not a filter field. -
setLabelFilter
Sets the caption (label) filter of the row/column fieldfield— Excel's "Label Filters" menu (ECMA-376 Part 1 §18.10.1.32). Items whose display label fails the condition are hidden on the nextrefresh(); the filter AND-combines with the manual item filter and any value filter on the same field.- Returns:
- whether the field exists on the row or column axis
-
clearLabelFilter
Clears the caption (label) filter offield. -
labelFilter
The caption (label) filter offield, or null when unfiltered. -
setValueFilter
Sets a single-threshold value filter on the row/column fieldfield: each item's aggregate of thedataField-th values-area entry is compared withtype; failing items (and items with no numeric aggregate) are hidden on the nextrefresh().- Returns:
- whether the field exists on the row or column axis and
dataFieldis a values-area position
-
setValueFilterBetween
PivotValueFilterType.BETWEENform:low <= aggregate <= high. -
clearValueFilter
Clears the value filter offield. -
valueFilter
The value filter offield, or null when unfiltered. -
sortField
Sorts the row/column fieldfieldby item label (ECMA-376 Part 1 §18.10.1.69sortType; BOR-PVE-014 NC1). Takes effect on the nextrefresh().- Returns:
- whether the field exists on the row or column axis
-
sortFieldByValue
Sorts the row/column fieldfieldby the aggregate of thedataField-th values-area entry (§18.10.1.72autoSortScope; BOR-PVE-014 R1). Ties keep source order.- Returns:
- whether the field exists on the row or column axis and
dataFieldis a values-area position
-
clearFieldSort
Restores manual/source item order forfield. -
fieldSort
The declared sort offield, or null for manual/source order. -
refresh
public int refresh()Re-reads the source range, runs the pivot cube engine (aggregation + layout), and materializes the computed output into the sheet at the pivot anchor — row labels, column headers, values, and grand totals become ordinary cells (like Excel's Refresh). The previous output region is overwritten.- Returns:
- the number of cells written
- Throws:
AxyraException- when the source range cannot be resolved
-