Safe Pivot worksheet materialization
Version 2.384.90 adds isolated Pivot evaluation and guarded worksheet result replacement; version 2.384.92 extends supported local sources to defined names and tables resolved at each call
Ordinary ODS Pivot translation
One qualified ordinary ODS data-pilot definition imports as an editable local-source Pivot cache and view, retaining the existing result cells and styles without rematerializing them on load; the model can be saved as XLSX with real Pivot parts or back to ODS
The ordinary aggregate profile requires exactly two adjacent local source columns, distinct string headers, one nonempty string row field, one finite numeric SUM, COUNT, AVERAGE, MIN or MAX field and at most 65536 source records, with DataFields[0].NumberFormat = 0
Newly authored views require the one-header-row layout, explicitly set with FirstDataRow := FirstRow + 1, and must complete MaterializeNativePivotTable before ODS export; after source edits call RefreshPivotCache and materialize again, and after changing an effective row, measure or grand-total caption materialize again
Export validates the current source, cache, result values, effective captions and materialization ownership before writing; source numbers must survive the existing ODS numeric writer unchanged, and aggregate values must equal the selected source aggregate or its explicit 15-significant-digit persisted form; AVERAGE additionally requires finite agreement between the source-order running mean and source-order sum/count under that projection
COUNT validates actual source-cache freshness even when the displayed count stays unchanged; distinct case-equivalent categories refuse because native and core grouping differ; whitespace remains category content, and no general floating-point tolerance is introduced
Unsupported or mixed imported collections retain the existing whole raw ODS representation, while unsupported typed ODS output is reported and refused before destination output; raw preservation does not promise original ZIP or lexical XML bytes
Imported raw OOXML caches require the explicit local refresh, measure-role declaration and materialization lifecycle before becoming eligible; multiple or advanced Pivots, other measures, native expanded members, filters, layout extensions and nondefault refresh or format settings remain outside this profile
Stored captions are retained, but another application's refresh may regenerate localized captions; category ordering, interactive buttons and cross-application style equivalence are not qualified
Typed admission bounds descriptor text, events, attributes and row allocations; the existing unsupported raw XML capture remains separate from these finite limits
Materialize a view
if Workbook.RefreshPivotCache(Pivot.CacheId) <> 1 then
raise Exception.Create('Pivot cache refresh failed');
if Workbook.MaterializePivotTable(Pivot) <> 1 then
raise Exception.Create('Pivot output cannot be replaced safely');
TXLSXWorkbook.MaterializePivotTable(ATable: TXLSPivotTable): Integer computes results from the current cache and places them at the view's FirstRow and FirstCol; it returns 1 on success or -1 for unsupported sources, unsafe destinations, evaluation failure, or a rejected workbook mutation
Refresh and worksheet recalculation remain explicit operations; successful materialization invalidates calculation dependencies so callers can recalculate downstream formulas when appropriate
The default overload accepts blank destination cells and unchanged cells previously owned by the same view; occupied unowned cells anywhere inside the complete output rectangle reject the operation, including gaps that the result writer does not fill
if Workbook.MaterializePivotTable(Pivot, True) <> 1 then
raise Exception.Create('Existing Pivot values cannot be adopted safely');
TXLSXWorkbook.MaterializePivotTable(ATable: TXLSPivotTable; AAdoptExisting: Boolean): Integer can explicitly adopt existing scalar cells inside the view's declared previous rectangle on its first materialization; it does not authorize replacing formulas, array members, rich text, metadata-bearing cells, or content outside that rectangle
Ownership, resizing, and movement
The view retains exact coordinates and typed value snapshots for written cells; XLSX saving preserves this ownership in the Pivot definition, so later updates can validate it after reopening
Changed typed content or a removed nonblank owned cell rejects the entire update; number subtypes share a canonical numeric representation, while text, Boolean values, and errors retain distinct identities
Shrinking or moving a result clears only unchanged owned values that are no longer produced; existing cell objects, formatting, and comments remain available, and unrelated cells remain outside the ownership set
Changing FirstRow or FirstCol moves the next output while the previous ownership coordinates remain available for cleanup; an empty result clears owned values and retains an anchor-only location
Updating date criteria after reopening
Changing supported date criteria after reopening does not require adopting Pivot cells again: save writes the current materialized values and result bounds together with the updated criteria, including workbooks with Slicer and Timeline selections
Isolated preview
function TXLSPivotTable.MakePreview(AWriter: TlxPivotResultWriter): Integer; property TXLSPivotTable.EvaluationSourceTable: TXLSPivotTable;
TXLSPivotTable.MakePreview uses independent copies of the cache and view, including calculated-field placeholders, and discards them after evaluation; ordinary Make retains its existing live-cache behavior
The writer receives zero-based row and column offsets and typed values; the return value follows Make's aggregate-cell count, which is separate from the number of writer calls; a missing cache or writer returns zero, and evaluation or writer exceptions propagate
Caller record predicates and registered owner filters remain active in previews, including workbook Slicer selections; callbacks receive the temporary evaluated view and its temporary cache
TXLSPivotTable.EvaluationSourceTable returns the live view for an ordinary evaluation and the original live view for a preview; use it when a callback needs to identify a connected view, while reading evaluated records from the callback's temporary Cache
Callback owners remain caller-owned; preview objects and their records must not be retained after the callback or preview call ends
OpenDocument DATA order and result ownership
The finite row-path and column-path DATA profiles select an actual measure ordinal from the supported 1..16-measure layout and derive complete parent-prefix aggregates before publishing an ordered result
Each selected occurrence retains its source field and aggregate function, including repeated references to the same source field; display captions do not identify DATA measures
Source edits require explicit cache refresh and OpenDocument rematerialization, while sort-setting edits require rematerialization of the current cache; whole-grid validation cannot combine individually matching cells from different result projections
The qualified column member caption profile also uses explicit RefreshPivotCache after source changes and MaterializeOdsPivotTable after caption edits or clearing, with source/cache identities, the old ownership ledger and physical header values checked together before replacement
A supported one-through-sixteen-measure column result uses its actual data width while retaining every represented real column axis; its complete field-header cells have separately checked sparse ownership, including headers beyond the data rectangle
Imported prior wide results keep their validated ownership for no-op saving, and explicit rematerialization can retire only their still-owned padding; a narrower result does not capture a whole rectangular area around its extra headers
Ordinary cells immediately to the right of the complete headers or below an outlying header remain protected; only the exact represented field-header positions belong to the sparse header plan
Unknown, malformed, stale or changed header ownership cannot authorize replacement, and matching text alone does not grant permission to adopt an occupied cell
Finite LibreOffice 26.2.5.2 qualification covers six row and column DATA layouts through open, explicit refresh, save and reopen, followed by typed library return with the original input streams and workbook owners released
Selected cases include eight-level row and column paths, uneven source-weighted averages, hidden row prefixes and a collapsed column prefix; the supported selected-measure extensions also retain complete column headers and source-bound native-generated grand captions through explicit refresh and typed reopening
These finite observations do not qualify every hierarchy, data set, locale, application version, provider or interactive combination
Safety boundaries
Materialization requires a view and cache registered in the same workbook and a supported local rectangular, defined-name, or table source; source resolution follows current names and table extents, and unsupported or unresolved sources reject before mutation
Current source geometry, other Pivot locations, structured tables, query result ranges, merged cells, and fixed or dynamic arrays cannot intersect the new output or old owned cells that need clearing; table totals remain protected even though they are excluded from cache records
Validation and output staging run under a read lease, followed by the normal workbook mutation guard and generation check; a frozen read-only workbook view rejects materialization without replacing cells or changing geometry
Filters must be read-only and follow the workbook's ordinary single-writer contract; isolation prevents normal preview calculations from changing the live cache, but arbitrary callback writes through separately captured live objects cannot be rolled back
This operation materializes the library's calculated result layout; complete native Pivot layout authoring, Slicer UI creation, and cross-filter no-data display evaluation remain separate capabilities
OpenDocument row-path headers and copied views
The represented two-through-eight-row-field profile retains one header row for one numeric measure and two header rows for multiple independent measure occurrences
In the two-header layout, the first row carries the view's explicit DataCaption at the first measure column and the second carries row-field and measure captions; successful MaterializeOdsPivotTable publishes that full geometry and the corresponding FirstDataRow together
The complete header and result must follow one supported whole-grid projection, so a one-row shift, a missing caption or individually changed result is refused rather than adopted as a similar layout
Within this local row-path profile, a metadata-only Pivot clone receives independent cache/view state without claiming the source's old result cells as destination ownership; provide its represented local source and explicitly materialize it before saving
A represented whole-worksheet graph copy moves cells, typed source/cache relationships, result ownership and exact sparse column-header ownership with the view coordinates and captions, preserving the row-path two-header data-start relationship where applicable
A metadata-only clone retains independent cache and view state without claiming destination result or header cells; it requires its represented local source and explicit safe materialization before saving a result
Stale ownership, unrelated occupied cells and foreign contexts do not gain overwrite permission through copying
These operations keep the normal source resolution, explicit refresh, collision, budget and workbook mutation checks, and do not add implicit refresh or general native-layout conversion
Supported homogeneous parent subtotals preserve an explicit source-owned caption through native refresh, while each measure and imported row subtotal retains its concrete aggregation
Single-measure SUM captions keep literal question marks and backslashes through the caption-template encoding; this does not admit arbitrary templates, mixed-function parent subtotals or changed result ownership