Class PivotTableView

java.lang.Object
io.keikai.axyra.sheets.PivotTableView

public final class PivotTableView extends Object
A live view of an existing pivot table, obtained via 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 Type
    Method
    Description
    void
    Defines a calculated field — a virtual source column whose value is formula evaluated over the sums of the referenced source fields within each pivot bucket (Excel's calculated-field semantics; ECMA-376 Part 1 §18.10.1.13 cacheField@formula).
    void
    addCalculatedItem(String field, String name, String formula)
    Defines a calculated item on the row/column field field — a virtual item whose per-cell value is formula evaluated over the field's other items (ECMA-376 Part 1 §18.10.1.9; e.g.
    void
    addColumnField(String sourceField)
    Adds sourceField to the column axis (nested innermost).
    void
    addDataField(String sourceField, AggregateFunction function)
    Adds sourceField to the values area with the default caption.
    void
    addDataField(String sourceField, AggregateFunction function, String customName)
    Adds sourceField to the values area.
    void
    addFilterField(String sourceField)
    Adds sourceField as a report filter (ECMA-376 page field).
    void
    addPageField(String sourceField)
    Alias of addFilterField(java.lang.String) using the OOXML "page field" name.
    void
    addRowField(String sourceField)
    Adds sourceField to the row axis (nested innermost).
    The calculated-field definitions, in definition order.
    The calculated-item definitions, in definition order.
    boolean
    Restores manual/source item order for field.
    boolean
    Clears the caption (label) filter of field.
    boolean
    clearShowDataAs(int position)
    Restores the raw aggregate for the position-th values field.
    boolean
    Clears the Top-N filter of field.
    boolean
    Clears the value filter of field.
    The column-axis fields, in nesting order.
    The values-area fields, in order.
    The grouping of field, or null when ungrouped.
    The declared sort of field, or null for manual/source order.
    The report-filter (page) fields.
    The grand-total caption override, or null (locale default).
    boolean
    Whether the grand-total column (right) is shown.
    boolean
    Whether the grand-total row (bottom) is shown.
    boolean
    Groups the row/column field field by a date component (ECMA-376 Part 1 §18.10.1.81 rangePr@groupBy): on refresh() the field's items become the component labels in calendar order (MONTHS -> "Jan".."Dec", QUARTERS -> "Qtr1".."Qtr4", …).
    boolean
    groupFieldByDate(String field, PivotDateGroupBy... components)
    Multi-level date grouping — Excel's Years/Quarters/Months expansion: components[0] becomes the outermost level.
    boolean
    groupFieldNumeric(String field, double start, double end, double interval)
    Groups the row/column field field into numeric bins of interval over [start, end] — Excel's label shapes ("0-9", last bin "90-100", outliers "<0" / ">100").
    int
    This pivot table's index on its sheet.
    The currently visible items of field's manual filter: the distinct source-column items minus the hidden ones.
    The caption (label) filter of field, or null when unfiltered.
    The report layout (compact / outline / tabular).
    The output anchor (e.g.
    void
    moveColumnField(int from, int to)
    Reorders column fields: moves position from to to.
    void
    moveDataField(int from, int to)
    Reorders data fields: moves position from to to.
    void
    moveRowField(int from, int to)
    Reorders row fields: moves position from to to.
    The pivot table name.
    The selected item of the report-filter (page) field field, or null for "(All)" — also null when the field is unknown or not a filter field.
    int
    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 (the refreshedBy attribute of pivotCacheDefinition, ECMA-376 Part 1 §18.10.1.67), or null when the source file carries none — as for a pivot table built through this API.
    void
    Re-read the pivot state from the engine.
    void
    Removes the calculated field name together with every values-area placement referencing it.
    void
    Removes the calculated item name from field.
    void
    removeColumnField(int position)
    Removes the position-th column field.
    void
    removeDataField(int position)
    Removes the position-th data (values) field.
    void
    removeFilterField(int position)
    Removes the position-th report-filter field.
    void
    removeRowField(int position)
    Removes the position-th row field (0-based nesting order).
    The row-axis fields, in nesting order.
    void
    setColumnFieldCaption(int position, String caption)
    Renames the position-th column field; see setRowFieldCaption(int, java.lang.String).
    void
    setColumnFieldSubtotals(int position, boolean show)
    Toggles subtotals for the position-th column field.
    void
    setFilterFieldCaption(int position, String caption)
    Renames the position-th report-filter field; see setRowFieldCaption(int, java.lang.String).
    void
    Sets the grand-total caption (ECMA-376 Part 1 §18.10.1.46); pass null to restore the locale default ("Grand Total").
    void
    setGrandTotals(boolean grandTotalRow, boolean grandTotalColumn)
    Toggles the grand-total row (bottom) and grand-total column (right).
    boolean
    setItemFilter(String field, String... visibleItems)
    Restricts field's manual item filter to visibleItems — Excel's filter dropdown with only those entries checked (ECMA-376 Part 1 §18.10.1.45 item@h).
    boolean
    Sets the caption (label) filter of the row/column field field — Excel's "Label Filters" menu (ECMA-376 Part 1 §18.10.1.32).
    void
    Sets the report layout (ECMA-376 Part 1 §18.10.1.73; BOR-PV-001).
    boolean
    setPageFilter(String field, String item)
    Selects a single item on the report-filter (page) field field — Excel's single-select page filter dropdown (ECMA-376 Part 1 §18.10.1.62 pageField@item).
    void
    setRowFieldCaption(int position, String caption)
    Renames the position-th row field for display (ECMA-376 Part 1 §18.10.1.69 pivotField@name — Excel writes this attribute when a placed field is renamed in the pivot UI); pass null to restore the source column name.
    void
    setRowFieldSubtotals(int position, boolean show)
    Toggles subtotals for the position-th row field.
    boolean
    setShowDataAs(int position, PivotShowDataAsType type)
    Sets the Show-Values-As mode of the position-th values-area field for the base-less modes (percent of total/row/column, running total, ranks, index).
    boolean
    setShowDataAs(int position, PivotShowDataAsType type, String baseField, String baseItem)
    Sets the Show-Values-As mode with base references: baseField names a row/column-placed field, baseItem one of its item labels.
    boolean
    Applies a named pivot style + banding flags (ECMA-376 Part 1 §18.10.1.88 pivotTableStyleInfo); Excel renders the bands on open.
    boolean
    Applies name with Excel's Design-tab default flags.
    boolean
    setTopNFilter(String field, int dataField, int count, boolean bottom)
    Keeps only the top (or bottom) count items of the row/column field field, ranked by their aggregate of the dataField-th values-area entry — Excel's "Top 10" value filter.
    boolean
    setTopPercentFilter(String field, int dataField, double percent, boolean bottom)
    Percent mode: keeps the top (or bottom) items whose aggregates accumulate to percent of the field's total.
    boolean
    setValueFilter(String field, int dataField, PivotValueFilterType type, double value)
    Sets a single-threshold value filter on the row/column field field: each item's aggregate of the dataField-th values-area entry is compared with type; failing items (and items with no numeric aggregate) are hidden on the next refresh().
    boolean
    setValueFilterBetween(String field, int dataField, double low, double high)
    PivotValueFilterType.BETWEEN form: low <= aggregate <= high.
    showDataAs(int position)
    The Show-Values-As state of the position-th values-area field, or null when the position is out of range.
    boolean
    sortField(String field, boolean ascending)
    Sorts the row/column field field by item label (ECMA-376 Part 1 §18.10.1.69 sortType; BOR-PVE-014 NC1).
    boolean
    sortFieldByValue(String field, boolean ascending, int dataField)
    Sorts the row/column field field by the aggregate of the dataField-th values-area entry (§18.10.1.72 autoSortScope; BOR-PVE-014 R1).
    The source column names available for field placement.
    The source data reference (e.g.
    The named pivot style, or null when none is applied.
    The Top-N filter of field, or null when unfiltered.
    boolean
    Removes field's grouping (items revert to the raw values).
    The value filter of field, or null when unfiltered.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public String name()
      The pivot table name.
    • location

      public String location()
      The output anchor (e.g. "H1").
    • sourceRef

      public String sourceRef()
      The source data reference (e.g. "Sheet1!A1:D10").
    • refreshedBy

      public String refreshedBy()
      The user name stamped on the pivot cache the last time it was refreshed (the refreshedBy attribute of pivotCacheDefinition, ECMA-376 Part 1 §18.10.1.67), or null when the source file carries none — as for a pivot table built through this API.
    • sourceFields

      public List<String> sourceFields()
      The source column names available for field placement.
    • addRowField

      public void addRowField(String sourceField)
      Adds sourceField to the row axis (nested innermost).
    • addColumnField

      public void addColumnField(String sourceField)
      Adds sourceField to the column axis (nested innermost).
    • addFilterField

      public void addFilterField(String sourceField)
      Adds sourceField as a report filter (ECMA-376 page field).
    • addPageField

      public void addPageField(String sourceField)
      Alias of addFilterField(java.lang.String) using the OOXML "page field" name.
    • addDataField

      public void addDataField(String sourceField, AggregateFunction function)
      Adds sourceField to the values area with the default caption.
    • addDataField

      public void addDataField(String sourceField, AggregateFunction function, String customName)
      Adds sourceField to the values area. customName overrides the "Sum of Sales"-style default caption (ECMA-376 Part 1 §18.10.1.18 dataField@name); pass null to keep the default.
    • removeRowField

      public void removeRowField(int position)
      Removes the position-th row field (0-based nesting order).
    • removeColumnField

      public void removeColumnField(int position)
      Removes the position-th column field.
    • removeFilterField

      public void removeFilterField(int position)
      Removes the position-th report-filter field.
    • removeDataField

      public void removeDataField(int position)
      Removes the position-th data (values) field.
    • moveRowField

      public void moveRowField(int from, int to)
      Reorders row fields: moves position from to to.
    • moveColumnField

      public void moveColumnField(int from, int to)
      Reorders column fields: moves position from to to.
    • moveDataField

      public void moveDataField(int from, int to)
      Reorders data fields: moves position from to to.
    • rowFields

      public List<PivotField> rowFields()
      The row-axis fields, in nesting order.
    • columnFields

      public List<PivotField> columnFields()
      The column-axis fields, in nesting order.
    • filterFields

      public List<PivotField> filterFields()
      The report-filter (page) fields.
    • dataFields

      public List<PivotField> dataFields()
      The values-area fields, in order.
    • layout

      public PivotLayout layout()
      The report layout (compact / outline / tabular).
    • setLayout

      public void setLayout(PivotLayout layout)
      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 is colGrandTotals and the right column is rowGrandTotals (ECMA-376 Part 1 §18.10.1.15 / §18.10.1.73 — the attribute names are counter-intuitive).
    • grandTotalCaption

      public String grandTotalCaption()
      The grand-total caption override, or null (locale default).
    • setGrandTotalCaption

      public void setGrandTotalCaption(String caption)
      Sets the grand-total caption (ECMA-376 Part 1 §18.10.1.46); pass null to restore the locale default ("Grand Total").
    • setRowFieldSubtotals

      public void setRowFieldSubtotals(int position, boolean show)
      Toggles subtotals for the position-th row field.
    • setColumnFieldSubtotals

      public void setColumnFieldSubtotals(int position, boolean show)
      Toggles subtotals for the position-th column field.
    • setRowFieldCaption

      public void setRowFieldCaption(int position, String caption)
      Renames the position-th row field for display (ECMA-376 Part 1 §18.10.1.69 pivotField@name — Excel writes this attribute when a placed field is renamed in the pivot UI); pass null to restore the source column name.
    • setColumnFieldCaption

      public void setColumnFieldCaption(int position, String caption)
      Renames the position-th column field; see setRowFieldCaption(int, java.lang.String).
    • setFilterFieldCaption

      public void setFilterFieldCaption(int position, String caption)
      Renames the position-th report-filter field; see setRowFieldCaption(int, java.lang.String).
    • setTopNFilter

      public boolean setTopNFilter(String field, int dataField, int count, boolean bottom)
      Keeps only the top (or bottom) count items of the row/column field field, ranked by their aggregate of the dataField-th values-area entry — Excel's "Top 10" value filter. AND-combines with the other filters on the next refresh(); ties keep source order.
      Returns:
      whether the field exists on the row or column axis and the parameters are valid
    • setTopPercentFilter

      public boolean setTopPercentFilter(String field, int dataField, double percent, boolean bottom)
      Percent mode: keeps the top (or bottom) items whose aggregates accumulate to percent of the field's total.
    • clearTopNFilter

      public boolean clearTopNFilter(String field)
      Clears the Top-N filter of field.
    • topNFilter

      public PivotTopNFilter topNFilter(String field)
      The Top-N filter of field, or null when unfiltered.
    • setStyle

      public boolean setStyle(PivotStyle style)
      Applies a named pivot style + banding flags (ECMA-376 Part 1 §18.10.1.88 pivotTableStyleInfo); Excel renders the bands on open. Pass null to clear.
      Returns:
      whether the pivot exists (and the name is non-empty when set)
    • setStyle

      public boolean setStyle(String name)
      Applies name with Excel's Design-tab default flags.
    • style

      public PivotStyle style()
      The named pivot style, or null when none is applied.
    • groupFieldByDate

      public boolean groupFieldByDate(String field, PivotDateGroupBy by)
      Groups the row/column field field by a date component (ECMA-376 Part 1 §18.10.1.81 rangePr@groupBy): on refresh() 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

      public boolean groupFieldByDate(String field, PivotDateGroupBy... components)
      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 on refresh(); 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

      public boolean groupFieldNumeric(String field, double start, double end, double interval)
      Groups the row/column field field into numeric bins of interval over [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

      public boolean ungroupField(String field)
      Removes field's grouping (items revert to the raw values).
    • fieldGroup

      public PivotFieldGroup fieldGroup(String field)
      The grouping of field, or null when ungrouped.
    • setShowDataAs

      public boolean setShowDataAs(int position, PivotShowDataAsType type)
      Sets the Show-Values-As mode of the position-th values-area field for the base-less modes (percent of total/row/column, running total, ranks, index). Applied post-aggregation on refresh(); percent modes produce fractions (Excel adds the % number format on top). PivotShowDataAsType.NORMAL restores the raw aggregate.
      Returns:
      whether position is 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: baseField names a row/column-placed field, baseItem one of its item labels. Both are required for PivotShowDataAsType.DIFFERENCE_FROM and PivotShowDataAsType.PERCENT_DIFFERENCE_FROM; baseField alone for PivotShowDataAsType.PERCENT_OF_PARENT (and it scopes PivotShowDataAsType.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 the position-th values field.
    • showDataAs

      public PivotShowDataAs showDataAs(int position)
      The Show-Values-As state of the position-th values-area field, or null when the position is out of range.
    • addCalculatedField

      public void addCalculatedField(String name, String formula)
      Defines a calculated field — a virtual source column whose value is formula evaluated over the sums of the referenced source fields within each pivot bucket (Excel's calculated-field semantics; ECMA-376 Part 1 §18.10.1.13 cacheField@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 with addDataField(String, AggregateFunction) using name, then refresh().

      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

      public void removeCalculatedField(String name)
      Removes the calculated field name together with every values-area placement referencing it.
      Throws:
      AxyraException - when no calculated field with that name exists
    • addCalculatedItem

      public void addCalculatedItem(String field, String name, String formula)
      Defines a calculated item on the row/column field field — a virtual item whose per-cell value is formula evaluated 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 next refresh().
      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

      public void removeCalculatedItem(String field, String name)
      Removes the calculated item name from field.
      Throws:
      AxyraException - when no such calculated item exists
    • calculatedItems

      public List<PivotCalculatedItem> calculatedItems()
      The calculated-item definitions, in definition order.
    • calculatedFields

      public List<PivotCalculatedField> calculatedFields()
      The calculated-field definitions, in definition order.
    • setItemFilter

      public boolean setItemFilter(String field, String... visibleItems)
      Restricts field's manual item filter to visibleItems — Excel's filter dropdown with only those entries checked (ECMA-376 Part 1 §18.10.1.45 item@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 next refresh().
      Returns:
      whether the field exists and is placed on an axis
    • itemFilter

      public String[] itemFilter(String field)
      The currently visible items of field'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

      public boolean setPageFilter(String field, String item)
      Selects a single item on the report-filter (page) field field — Excel's single-select page filter dropdown (ECMA-376 Part 1 §18.10.1.62 pageField@item). Pass null to restore "(All)". Takes effect on the next refresh().
      Returns:
      whether the field exists in the filter (page) area
    • pageFilter

      public String pageFilter(String field)
      The selected item of the report-filter (page) field field, or null for "(All)" — also null when the field is unknown or not a filter field.
    • setLabelFilter

      public boolean setLabelFilter(String field, PivotLabelFilterType type, String value)
      Sets the caption (label) filter of the row/column field field — Excel's "Label Filters" menu (ECMA-376 Part 1 §18.10.1.32). Items whose display label fails the condition are hidden on the next refresh(); 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

      public boolean clearLabelFilter(String field)
      Clears the caption (label) filter of field.
    • labelFilter

      public PivotLabelFilter labelFilter(String field)
      The caption (label) filter of field, or null when unfiltered.
    • setValueFilter

      public boolean setValueFilter(String field, int dataField, PivotValueFilterType type, double value)
      Sets a single-threshold value filter on the row/column field field: each item's aggregate of the dataField-th values-area entry is compared with type; failing items (and items with no numeric aggregate) are hidden on the next refresh().
      Returns:
      whether the field exists on the row or column axis and dataField is a values-area position
    • setValueFilterBetween

      public boolean setValueFilterBetween(String field, int dataField, double low, double high)
      PivotValueFilterType.BETWEEN form: low <= aggregate <= high.
    • clearValueFilter

      public boolean clearValueFilter(String field)
      Clears the value filter of field.
    • valueFilter

      public PivotValueFilter valueFilter(String field)
      The value filter of field, or null when unfiltered.
    • sortField

      public boolean sortField(String field, boolean ascending)
      Sorts the row/column field field by item label (ECMA-376 Part 1 §18.10.1.69 sortType; BOR-PVE-014 NC1). Takes effect on the next refresh().
      Returns:
      whether the field exists on the row or column axis
    • sortFieldByValue

      public boolean sortFieldByValue(String field, boolean ascending, int dataField)
      Sorts the row/column field field by the aggregate of the dataField-th values-area entry (§18.10.1.72 autoSortScope; BOR-PVE-014 R1). Ties keep source order.
      Returns:
      whether the field exists on the row or column axis and dataField is a values-area position
    • clearFieldSort

      public boolean clearFieldSort(String field)
      Restores manual/source item order for field.
    • fieldSort

      public PivotFieldSort fieldSort(String field)
      The declared sort of field, 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