Class PivotTableView
refresh() that writes its output into the sheet.
Obtain it with Sheet.pivotTable(int) or
Sheet.pivotTable(String); create a pivot with
Sheet.addPivotTable(String, String, String).
try (Workbook wb = Workbook.create()) {
Sheet s = wb.createSheet("Data");
s.range("A1:B3").setValues(new CellValue[][] {
{CellValue.text("Region"), CellValue.text("Sales")},
{CellValue.text("East"), CellValue.number(100)},
{CellValue.text("West"), CellValue.number(250)}});
int index = s.addPivotTable("Pivot1", "D1", "Data!A1:B3");
PivotTableView pv = s.pivotTable(index);
pv.addRowField("Region");
pv.addDataField("Sales", AggregateFunction.SUM);
pv.refresh(); // writes the output cells
CellValue[][] out = s.range(pv.location()).values(); // the whole output range
}
Definition and output. Mutators change only the pivot's
definition in the engine, at once. They do not change any cell. Call
refresh() to write the new output into the sheet before you read
its cells: a cell read never refreshes a pivot. A pivot created or changed
through the API and not refreshed since is refreshed automatically before
the workbook is saved (every Workbook.save* method) or rendered
(Workbook.renderPdf, renderSheet*, renderRange*,
Sheet.renderChartToPng(int, int, int), Sheet.renderChartToSvg(int, int, int)). That
automatic refresh replaces the output the file carried; when it cannot read
the source range, the save or render goes on without it. A mutator that
returns false or throws still marks the pivot for this automatic
refresh. A pivot read from a file and never changed keeps the output the
file carried. Workbook.setTimelineRange(java.lang.String, java.time.LocalDate, java.time.LocalDate) and
Workbook.setSlicerSelection(java.lang.String, java.lang.String...) refresh the pivots they filter at once.
Snapshot. Getters read a snapshot of the definition taken when
the view was created, by reload(), and after each successful
mutator called through this view. Changes made through another view of the
same pivot appear only after reload(). itemFilter(java.lang.String) and
pageFilter(java.lang.String) always read the engine. The view is bound to the
pivot's index on its sheet; a pivot removed or inserted before it moves
that index.
Fields. Field placement follows the Excel model (ECMA-376 Part 1
§18.10): source columns go to the row, column or 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" and
"Count of Sales"). Methods that take a position, from,
to or dataField use 0-based positions within one area; a
negative position is treated as past the end.
Saving. A changed pivot is written from the model on the next
save, not from the bytes read from the file, and its cache is marked
refreshOnLoad.
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)), value filters (setValueFilter(java.lang.String, int, io.keikai.axyra.sheets.PivotValueFilterType, double)) and
Top-N filters (setTopNFilter(java.lang.String, int, int, boolean)). Items sort by label or by a data
field's aggregate (sortField(java.lang.String, boolean), sortFieldByValue(java.lang.String, boolean, int)). Values
transform with setShowDataAs(int, io.keikai.axyra.sheets.PivotShowDataAsType). Virtual columns come from
addCalculatedField(java.lang.String, java.lang.String), virtual items from addCalculatedItem(java.lang.String, java.lang.String, java.lang.String).
Items group by date or numeric range with groupFieldByDate(java.lang.String, io.keikai.axyra.sheets.PivotDateGroupBy) and
groupFieldNumeric(java.lang.String, double, double, double). Named styles come from setStyle(io.keikai.axyra.sheets.PivotStyle).
-
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 as the innermost level.voidaddDataField(String sourceField, AggregateFunction function) AddssourceFieldto the values area with the "Sum of Sales"-style default caption.voidaddDataField(String sourceField, AggregateFunction function, String customName) AddssourceFieldto the values area with a caption.voidaddFilterField(String sourceField) AddssourceFieldas a report filter: Excel's Filters area, an ECMA-376 page field.voidaddPageField(String sourceField) Same asaddFilterField(java.lang.String), under the OOXML "page field" name.voidaddRowField(String sourceField) AddssourceFieldto the row axis as the innermost level.The calculated-field definitions, in definition order.The calculated-item definitions, in definition order.booleanclearFieldSort(String field) Restores manual or source item order for the row/column fieldfield.booleanclearLabelFilter(String field) Clears the caption (label) filter of the row/column fieldfield.booleanclearShowDataAs(int position) Restores the raw aggregate for theposition-th values-area field and clears its base references.booleanclearTopNFilter(String field) Clears the Top-N filter of the row/column fieldfield.booleanclearValueFilter(String field) Clears the value filter of the row/column fieldfield.The column-axis fields in nesting order, outermost first.The values-area fields in order.fieldGroup(String field) The grouping of the row/column fieldfield, matched ignoring case.The declared sort of the row/column fieldfield, matched ignoring case.The report-filter (page) fields in order.The grand-total caption override, ornullwhen the default ("Grand Total") applies.booleanWhether the grand-total column at the right is shown, as of the lastreload().booleanWhether the grand-total row at the bottom is shown, as of the lastreload().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 0-based index on its sheet, fixed when the view was created.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 of the row/column fieldfield, matched ignoring case.layout()The report layout (compact, outline or tabular), as of the lastreload().location()The pivot's output location in A1 form, without a sheet name.voidmoveColumnField(int from, int to) voidmoveDataField(int from, int to) voidmoveRowField(int from, int to) Moves the row field atfromto positionto; the fields between shift by one.name()The pivot table's name, as of the lastreload().pageFilter(String field) The selected item of the report-filter (page) fieldfield.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-reads the pivot definition from the engine into this view's snapshot.voidremoveCalculatedField(String name) Removes the calculated fieldname, matched ignoring ASCII case, together with every values-area placement referencing it.voidremoveCalculatedItem(String field, String name) Removes the calculated itemnamefromfield.voidremoveColumnField(int position) Removes theposition-th column field; seeremoveRowField(int).voidremoveDataField(int position) Removes theposition-th values-area field.voidremoveFilterField(int position) Removes theposition-th report-filter field and clears its selected item; seeremoveRowField(int).voidremoveRowField(int position) Removes theposition-th row field.The row-axis fields in nesting order, outermost first.voidsetColumnFieldCaption(int position, String caption) Renames theposition-th column field for display; seesetRowFieldCaption(int, java.lang.String).voidsetColumnFieldSubtotals(int position, boolean show) Shows or hides the subtotals of theposition-th column field; seesetRowFieldSubtotals(int, boolean).voidsetFilterFieldCaption(int position, String caption) Renames theposition-th report-filter field for display; seesetRowFieldCaption(int, java.lang.String).voidsetGrandTotalCaption(String caption) Sets the grand-total caption (ECMA-376 Part 1 §18.10.1.46).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).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).voidsetRowFieldSubtotals(int position, boolean show) Shows or hides the subtotals of theposition-th row field (ECMA-376pivotField@defaultSubtotal).booleansetShowDataAs(int position, PivotShowDataAsType type) Sets the Show-Values-As mode of theposition-th values-area field without base references.booleansetShowDataAs(int position, PivotShowDataAsType type, String baseField, String baseItem) Sets the Show-Values-As mode of theposition-th values-area field with base references.booleansetStyle(PivotStyle style) Applies a named pivot style + banding flags (ECMA-376 Part 1 §18.10.1.88pivotTableStyleInfo); Excel renders the bands on open.booleanApplies the stylenamewith Excel's Design-tab default flags (PivotStyle.of(String));nullclears the style.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 field: Excel's "Top 10" filter.booleansetTopPercentFilter(String field, int dataField, double percent, boolean bottom) Keeps the top (or bottom) items offieldwhose aggregates, taken in rank order, first reachpercentpercent of the field's total: Excel's "Top 10 ...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 field is compared withvaluebytype.booleansetValueFilterBetween(String field, int dataField, double low, double high) Hides the items of the row/column fieldfieldwhose aggregate of thedataField-th values-area field is outsidelow <= aggregate <= high: Excel's "between" value filter.showDataAs(int position) The Show-Values-As state of theposition-th values-area field, read from this view's snapshot.booleanSorts the row/column fieldfieldby item label (ECMA-376 Part 1 §18.10.1.69sortType).booleansortFieldByValue(String field, boolean ascending, int dataField) Sorts the row/column fieldfieldby its aggregate of thedataField-th values-area field (ECMA-376 Part 1 §18.10.1.72autoSortScope).The source column names available for field placement, in source order: the cache field names, or the header row of the source range for a pivot whose cache is still empty.The source data reference, e.g.style()The named pivot style and its banding flags, read from this view's snapshot.topNFilter(String field) The Top-N filter of the row/column fieldfield, matched ignoring case.booleanungroupField(String field) Removes the grouping offield: items revert to the raw source values, and a multi-level date grouping collapses back to one level.valueFilter(String field) The value filter of the row/column fieldfield, matched ignoring case.
-
Method Details
-
reload
public void reload()Re-reads the pivot definition from the engine into this view's snapshot. Getters other thanitemFilter(java.lang.String)andpageFilter(java.lang.String)return what this call read. It does not refresh the output; seerefresh().- Throws:
AxyraException- when the sheet no longer has a pivot at this view's index
-
index
public int index()This pivot table's 0-based index on its sheet, fixed when the view was created. -
name
The pivot table's name, as of the lastreload(). -
location
The pivot's output location in A1 form, without a sheet name. It is the anchor cell (e.g."H1") for a pivot created through the API and not yet refreshed. Otherwise it is the whole output range (e.g."H1:J8"), as read from the file or as written by the lastrefresh(). Read from this view's snapshot. -
sourceRef
The source data reference, e.g."Sheet1!A1:D10", as of the lastreload(). -
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, in source order: the cache field names, or the header row of the source range for a pivot whose cache is still empty. Calculated fields are not listed; seecalculatedFields().- Returns:
- an immutable snapshot as of the last
reload(); empty when the source range cannot be read
-
addRowField
AddssourceFieldto the row axis as the innermost level. The name matches a source column exactly first, then ignoring ASCII case. A field already placed on another axis is not moved; it gets a second placement. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Throws:
AxyraException- whensourceFieldis not a source column, or names a calculated field (calculated fields go only to the values area)
-
addColumnField
AddssourceFieldto the column axis as the innermost level. Name matching, placement and refresh behave as inaddRowField(java.lang.String).- Throws:
AxyraException- whensourceFieldis not a source column, or names a calculated field
-
addFilterField
AddssourceFieldas a report filter: Excel's Filters area, an ECMA-376 page field. Select its item withsetPageFilter(java.lang.String, java.lang.String). Name matching, placement and refresh behave as inaddRowField(java.lang.String).- Throws:
AxyraException- whensourceFieldis not a source column, or names a calculated field
-
addPageField
Same asaddFilterField(java.lang.String), under the OOXML "page field" name.- Throws:
AxyraException- whensourceFieldis not a source column, or names a calculated field
-
addDataField
AddssourceFieldto the values area with the "Sum of Sales"-style default caption. The same field may be added several times, with the same or another function. A calculated field fromaddCalculatedField(java.lang.String, java.lang.String)is accepted. The name matches exactly first, then ignoring ASCII case. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Throws:
AxyraException- whensourceFieldis neither a source column nor a calculated fieldNullPointerException- whenfunctionisnull
-
addDataField
AddssourceFieldto the values area with a caption.customNamereplaces the "Sum of Sales"-style default caption (ECMA-376 Part 1 §18.10.1.18dataField@name);nullor an empty string keeps the default. Otherwise the same asaddDataField(String, AggregateFunction).- Throws:
AxyraException- whensourceFieldis neither a source column nor a calculated fieldNullPointerException- whenfunctionisnull
-
removeRowField
public void removeRowField(int position) Removes theposition-th row field. The field returns to the unplaced field list and loses its manual item filter; when the same source column has another placement, this placement is deleted instead. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
position- 0-based nesting position, outermost first- Throws:
AxyraException- whenpositionis negative or past the last row field
-
removeColumnField
public void removeColumnField(int position) Removes theposition-th column field; seeremoveRowField(int).- Parameters:
position- 0-based nesting position, outermost first- Throws:
AxyraException- whenpositionis negative or past the last column field
-
removeFilterField
public void removeFilterField(int position) Removes theposition-th report-filter field and clears its selected item; seeremoveRowField(int).- Parameters:
position- 0-based position among the filter fields- Throws:
AxyraException- whenpositionis negative or past the last filter field
-
removeDataField
public void removeDataField(int position) Removes theposition-th values-area field. The positions of the fields after it drop by one. A value filter, Top-N filter or by-value sort keeps itsdataFieldnumber. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
position- 0-based values-area position- Throws:
AxyraException- whenpositionis negative or past the last values-area field
-
moveRowField
public void moveRowField(int from, int to) Moves the row field atfromto positionto; the fields between shift by one. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
from- 0-based current positionto- 0-based target position- Throws:
AxyraException- whenfromortois negative or past the last row field
-
moveColumnField
public void moveColumnField(int from, int to) - Parameters:
from- 0-based current positionto- 0-based target position- Throws:
AxyraException- whenfromortois negative or past the last column field
-
moveDataField
public void moveDataField(int from, int to) Moves the values-area field atfromto positionto; seemoveRowField(int, int). The field keeps its Show-Values-As setting. A value filter, Top-N filter or by-value sort keeps itsdataFieldnumber, so it then reads the field now at that position.- Parameters:
from- 0-based current positionto- 0-based target position- Throws:
AxyraException- whenfromortois negative or past the last values-area field
-
rowFields
The row-axis fields in nesting order, outermost first. A field grouped by several date components appears once per component.- Returns:
- a new list, a snapshot as of the last
reload()
-
columnFields
The column-axis fields in nesting order, outermost first. A field grouped by several date components appears once per component.- Returns:
- a new list, a snapshot as of the last
reload()
-
filterFields
The report-filter (page) fields in order.- Returns:
- a new list, a snapshot as of the last
reload()
-
dataFields
The values-area fields in order. Their list positions are thepositionanddataFieldarguments of the other methods.PivotField.showSubtotals()is alwaystruehere.- Returns:
- a new list, a snapshot as of the last
reload()
-
layout
The report layout (compact, outline or tabular), as of the lastreload(). -
setLayout
Sets the report layout (ECMA-376 Part 1 §18.10.1.73). The output changes on the nextrefresh(); a save or render refreshes it automatically.- Throws:
NullPointerException- whenlayoutisnull
-
grandTotalRow
public boolean grandTotalRow()Whether the grand-total row at the bottom is shown, as of the lastreload(). -
grandTotalColumn
public boolean grandTotalColumn()Whether the grand-total column at the right is shown, as of the lastreload(). -
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). The output changes on the nextrefresh(); a save or render refreshes it automatically. -
grandTotalCaption
The grand-total caption override, ornullwhen the default ("Grand Total") applies. Read from this view's snapshot. -
setGrandTotalCaption
Sets the grand-total caption (ECMA-376 Part 1 §18.10.1.46).nullor an empty string restores the default ("Grand Total"). The output changes on the nextrefresh(); a save or render refreshes it automatically. -
setRowFieldSubtotals
public void setRowFieldSubtotals(int position, boolean show) Shows or hides the subtotals of theposition-th row field (ECMA-376pivotField@defaultSubtotal). The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
position- 0-based nesting position, outermost first- Throws:
AxyraException- whenpositionis negative or past the last row field
-
setColumnFieldSubtotals
public void setColumnFieldSubtotals(int position, boolean show) Shows or hides the subtotals of theposition-th column field; seesetRowFieldSubtotals(int, boolean).- Parameters:
position- 0-based nesting position, outermost first- Throws:
AxyraException- whenpositionis negative or past the last 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).nullor an empty string restores the source column name. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
position- 0-based nesting position, outermost first- Throws:
AxyraException- whenpositionis negative or past the last row field
-
setColumnFieldCaption
Renames theposition-th column field for display; seesetRowFieldCaption(int, java.lang.String).- Parameters:
position- 0-based nesting position, outermost first- Throws:
AxyraException- whenpositionis negative or past the last column field
-
setFilterFieldCaption
Renames theposition-th report-filter field for display; seesetRowFieldCaption(int, java.lang.String).- Parameters:
position- 0-based position among the filter fields- Throws:
AxyraException- whenpositionis negative or past the last filter field
-
setTopNFilter
Keeps only the top (or bottom)countitems of the row/column fieldfield, ranked by their aggregate of thedataField-th values-area field: Excel's "Top 10" filter. It replaces the field's previous Top-N filter and AND-combines with the other filters. Ties keep source order; items with no numeric aggregate are hidden. The output changes on the nextrefresh(); a save or render refreshes it automatically. UsesetTopPercentFilter(java.lang.String, int, double, boolean)for the percent form.- Parameters:
dataField- 0-based values-area position; a negative value clears the field's Top-N filter, asclearTopNFilter(java.lang.String)doescount- number of items to keep; must be positivebottom-truekeeps the smallest items instead of the largest- Returns:
falsewhenfieldis not on the row or column axis,count <= 0, ordataFieldis past the last values-area field
-
setTopPercentFilter
Keeps the top (or bottom) items offieldwhose aggregates, taken in rank order, first reachpercentpercent of the field's total: Excel's "Top 10 ... Percent" filter. It replaces the field's previous Top-N filter. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
dataField- 0-based values-area position; a negative value clears the field's Top-N filterpercent- percent of the total, 0 to 100 (10 means 10 %); must be positivebottom-trueranks from the smallest aggregate- Returns:
falsewhenfieldis not on the row or column axis,percent <= 0, ordataFieldis past the last values-area field
-
clearTopNFilter
Clears the Top-N filter of the row/column fieldfield. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Returns:
falsewhenfieldis not on the row or column axis
-
topNFilter
The Top-N filter of the row/column fieldfield, matched ignoring case. Read from this view's snapshot.- Returns:
- the filter, or
nullwhen the field has none or is not on the row or column axis
-
setStyle
Applies a named pivot style + banding flags (ECMA-376 Part 1 §18.10.1.88pivotTableStyleInfo); Excel renders the bands on open. Passnullto clear the style. The name is not checked against Excel's built-in list; a name Excel does not know is written as given.- Returns:
falsewhen the style name is empty or blank, or the pivot no longer exists
-
setStyle
Applies the stylenamewith Excel's Design-tab default flags (PivotStyle.of(String));nullclears the style.- Returns:
falsewhennameis empty or blank, or the pivot no longer exists
-
style
The named pivot style and its banding flags, read from this view's snapshot.- Returns:
- the style, or
nullwhen 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. It replaces a previous date grouping of the field. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Returns:
falsewhenfieldis not on the row or column axis- Throws:
NullPointerException- whenbyisnull
-
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. Each component becomes its own row or column level, sorowFields()lists the field once per component andfieldGroup(java.lang.String)reports the outermost component. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
components- the date components, coarsest first, e.g.YEARS, QUARTERS, MONTHS- Returns:
falsewhenfieldis not on the row or column axis, orcomponentsisnull, empty or has a repeated component- Throws:
NullPointerException- when an element ofcomponentsisnull
-
groupFieldNumeric
Groups the row/column fieldfieldinto numeric bins ofintervalover[start, end]— Excel's label shapes ("0-9", last bin"90-100", outliers"<0"/">100"). Values belowstartor aboveendfall into the outlier bins. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Returns:
falsewhenfieldis not on the row or column axis,interval <= 0,end <= start, orstartorendis not finite
-
ungroupField
Removes the grouping offield: items revert to the raw source values, and a multi-level date grouping collapses back to one level. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Returns:
falsewhenfieldis not on the row or column axis or is not grouped
-
fieldGroup
The grouping of the row/column fieldfield, matched ignoring case. For a multi-level date grouping this is the outermost component. Read from this view's snapshot.- Returns:
- the grouping, or
nullwhen the field is ungrouped or not on the row or column axis
-
setShowDataAs
Sets the Show-Values-As mode of theposition-th values-area field without base references. Use it for the modes that need no base (percent of total, row or column, index). A mode that uses a base field or item takes ECMA-376's default: the first row field (or the first column field when there is no row field) and its first item; name the base withsetShowDataAs(int, PivotShowDataAsType, String, String). Percent modes produce fractions (0.25 means 25 %).PivotShowDataAsType.NORMALrestores the raw aggregate. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
position- 0-based values-area position- Returns:
falsewhenpositionis negative or past the last values-area field- Throws:
NullPointerException- whentypeisnull
-
setShowDataAs
public boolean setShowDataAs(int position, PivotShowDataAsType type, String baseField, String baseItem) Sets the Show-Values-As mode of theposition-th values-area field with base references.baseFieldnames a field placed on the row or column axis;baseItemis one of its item labels.PivotShowDataAsType.DIFFERENCE_FROM,PivotShowDataAsType.PERCENT_DIFFERENCE_FROMandPivotShowDataAsType.PERCENT_OFuse both.PivotShowDataAsType.PERCENT_OF_PARENT,PivotShowDataAsType.RUNNING_TOTAL,PivotShowDataAsType.RUNNING_TOTAL_PERCENTand the rank modes usebaseFieldas their level. Anullbase takes ECMA-376's default: the first row field (or first column field) and its first item.baseItemis not checked here; a label that matches no item leaves the affected cells blank after refresh.PivotShowDataAsType.NORMALrestores the raw aggregate and clears both base references. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
position- 0-based values-area positionbaseField- a row or column field name (matched exactly, then ignoring ASCII case), ornullbaseItem- an item label of the base field, ornull- Returns:
falsewhenpositionis negative or past the last values-area field, or a namedbaseFieldis not on the row or column axis- Throws:
NullPointerException- whentypeisnull
-
clearShowDataAs
public boolean clearShowDataAs(int position) Restores the raw aggregate for theposition-th values-area field and clears its base references. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
position- 0-based values-area position- Returns:
falsewhenpositionis negative or past the last values-area field
-
showDataAs
The Show-Values-As state of theposition-th values-area field, read from this view's snapshot. Every mode the engine reads from a file has aPivotShowDataAsTypeconstant.- Parameters:
position- 0-based values-area position- Returns:
- the state (
PivotShowDataAsType.NORMALfor a raw aggregate), ornullwhenpositionis negative or past the last values-area field
-
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(). A save or render refreshes a changed pivot automatically.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- whennameis blank or clashes (ignoring ASCII case) with a source column or an existing calculated field, or the formula does not parse, references itself, or references a name that is not a source column
-
removeCalculatedField
Removes the calculated fieldname, matched ignoring ASCII case, together with every values-area placement referencing it. The output changes on the nextrefresh(); a save or render refreshes it automatically.- 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. The output changes on the nextrefresh(); a save or render refreshes it automatically.- 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. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Throws:
AxyraException- when no such calculated item exists
-
calculatedItems
The calculated-item definitions, in definition order.- Returns:
- a new list, a snapshot as of the last
reload()
-
calculatedFields
The calculated-field definitions, in definition order.- Returns:
- a new list, a snapshot as of the last
reload()
-
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, ornull, clears the filter (every item visible). Values not present in the source column are ignored; when none ofvisibleItemsoccurs there, every item is hidden. Items match by exact display text. The field must be placed on the row, column or filter axis. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Returns:
falsewhenfieldis not a source column or not placed on the row, column or filter axis, or the source range cannot be read
-
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. It reads the engine, not this view's snapshot.- Returns:
- the visible items in first-appearance order, or
nullwhen the field is unknown, not placed on the row, column or filter axis, or the source range cannot be read
-
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). Passnullor an empty string to restore "(All)". The item is not checked against the source; a value absent from the source column leaves the pivot empty. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Returns:
falsewhenfieldis not a report-filter (page) field
-
pageFilter
The selected item of the report-filter (page) fieldfield. It reads the engine, not this view's snapshot.- Returns:
- the item, or
nullfor "(All)"; alsonullwhen 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. It replaces the field's previous label filter. Matching ignores ASCII case only;?and*match themselves, they are not wildcards. UseclearLabelFilter(java.lang.String)to remove the filter.- Returns:
falsewhenfieldis not on the row or column axis- Throws:
NullPointerException- whentypeisnull
-
clearLabelFilter
Clears the caption (label) filter of the row/column fieldfield. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Returns:
falsewhenfieldis not on the row or column axis
-
labelFilter
The caption (label) filter of the row/column fieldfield, matched ignoring case. Read from this view's snapshot.- Returns:
- the filter, or
nullwhen the field has none or is not on the row or column axis
-
setValueFilter
Sets a single-threshold value filter on the row/column fieldfield: each item's aggregate of thedataField-th values-area field is compared withvaluebytype. Failing items, and items with no numeric aggregate, are hidden. It replaces the field's previous value filter and AND-combines with the other filters. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
dataField- 0-based values-area position- Returns:
falsewhenfieldis not on the row or column axis, ordataFieldis negative or past the last values-area field- Throws:
IllegalArgumentException- whentypeisPivotValueFilterType.BETWEEN; usesetValueFilterBetween(java.lang.String, int, double, double)NullPointerException- whentypeisnull
-
setValueFilterBetween
Hides the items of the row/column fieldfieldwhose aggregate of thedataField-th values-area field is outsidelow <= aggregate <= high: Excel's "between" value filter. Items with no numeric aggregate are hidden. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Parameters:
dataField- 0-based values-area positionlow- the inclusive lower boundhigh- the inclusive upper bound- Returns:
falsewhenfieldis not on the row or column axis, ordataFieldis negative or past the last values-area field
-
clearValueFilter
Clears the value filter of the row/column fieldfield. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Returns:
falsewhenfieldis not on the row or column axis
-
valueFilter
The value filter of the row/column fieldfield, matched ignoring case. Read from this view's snapshot.- Returns:
- the filter, or
nullwhen the field has none or is not on the row or column axis
-
sortField
Sorts the row/column fieldfieldby item label (ECMA-376 Part 1 §18.10.1.69sortType). The output changes on the nextrefresh(); a save or render refreshes it automatically. UsesortFieldByValue(java.lang.String, boolean, int)to sort by a values-area aggregate.- Returns:
falsewhenfieldis not on the row or column axis
-
sortFieldByValue
Sorts the row/column fieldfieldby its aggregate of thedataField-th values-area field (ECMA-376 Part 1 §18.10.1.72autoSortScope). Ties keep source order. The sort may be declared before the values area has fields; the position is resolved at refresh. The output changes on the nextrefresh(); a save or render refreshes it automatically. UsesortField(java.lang.String, boolean)to sort by label.- Parameters:
dataField- 0-based values-area position; a negative value sorts by label instead- Returns:
falsewhenfieldis not on the row or column axis, or the values area has fields anddataFieldis past the last one
-
clearFieldSort
Restores manual or source item order for the row/column fieldfield. The output changes on the nextrefresh(); a save or render refreshes it automatically.- Returns:
falsewhenfieldis not on the row or column axis
-
fieldSort
The declared sort of the row/column fieldfield, matched ignoring case. Read from this view's snapshot.- Returns:
- the sort, or
nullwhen none is declared and when the field is not on the row or column axis. Without a sort the items keep the order the pivot declares for them, or ascending order for a field that declares none, as Excel lists a new pivot's items
-
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 rectangle is cleared first, so a shrinking table leaves no stale cells. A timeline bound to this pivot narrows the source records. Formulas that read the output are marked for recalculation.Call it after a change and before reading output cells; a cell read does not refresh. A save or render runs it automatically for a pivot created or changed through the API. Afterwards
location()returns the new output range, and the snapshot is reloaded.- Returns:
- the number of cells written
- Throws:
AxyraException- when the source range cannot be resolved, or the sheet no longer has a pivot at this view's index
-