Repository navigation
Calc: open without recalculating (file.open recalculate:false; honour manual calc mode) - #1465
sky-helper wants to merge 1 commit into
Conversation
… manual calc mode)
GridCraft calculated every formula again whenever a workbook opened. A
workbook that has to read exactly as it was saved (an approval form, a
signed report) then showed the day it was viewed in TODAY(), and any
difference between calculation engines as changed numbers. A workbook
saved in manual calculation mode was calculated on open all the same.
file.open takes {recalculate?: bool}. false opens the workbook with the
results stored in the file, array results included; true always
calculates. Without it, formulas are calculated again as before, unless
the workbook was saved in manual calculation mode and doesn't ask to be
calculated on load: an .xlsx with fullCalcOnLoad, an .xls with an
Uncalced record, or a workbook whose cached array results couldn't be
kept does ask. The result says whether it `recalculated`; a non-boolean
`recalculate` is refused before the file is read. A path that is
already open is switched to as it is, and the result says
`recalculateIgnored` when `recalculate` was given. A formula stored
without a result opens blank until it is calculated.
Behaviour change: a manual-mode .xlsx or .xls that doesn't ask to be
calculated on load now opens with its stored results by default, in
every entry point that opens through file.open without `recalculate`:
the desktop and web UI, the CLI (convert, info, cat, eval --in, run --in,
mcp --in), MCP open_workbook and the control channel's app.open.
Automatic-mode workbooks are unchanged.
After opening with stored results the dependency graph is built anyway.
In automatic mode an edit recalculates the formulas that depend on it
and, as after any edit, the formulas GridCraft always recalculates with
their dependents: volatile functions, INDIRECT, OFFSET, and formulas
using names (defined names, LET/LAMBDA variables), table references or
unknown functions. The first edit can therefore change those from their
stored results even when it is unrelated to them. In manual mode an edit
calculates the formulas it enters; Calculate Now (F9) calculates
everything. Manual mode is honoured on open only: structural edits
(inserting or deleting rows, columns, cells or sheets, sorting,
filtering, grouping, hiding, row heights) still recalculate the whole
workbook whatever the mode.
CalcSettings::full_calc_on_load records that the stored results are out
of date or incomplete. XLSX reads calcPr fullCalcOnLoad and writes it
back while it is set (as well as, as before, when a formula has no
cached result); XLS maps Uncalced (0x005E) to it; a full recalculation
clears it.
To show array results without calculating, the XLSX and XLS readers keep
the values cached in an array formula's range as the values it spilled
(Sheet::spill / spill_ranges) instead of dropping them (storytold#156). A
recalculation still clears them and lays the range out again from the
formula, so opening with recalculation is unchanged. A range keeps them
only when it starts at its formula, holds at most 1 million cells (what
the writer caches for one range; MAX_CACHED_RANGE_CELLS is shared) and
fits in 4 million cells per workbook, since a file names a range for
free while later edits and saves walk it. Otherwise they are dropped as
before and the workbook is marked full_calc_on_load, so a manual-mode
workbook opens calculated and a save asks the next reader to calculate.
view.newWindow no longer calculates its copy: a second window on the
same workbook shows the same results and the circular references found
so far.
GridCraft's JSON format doesn't store spilled values, so a manual-mode
JSON workbook opens with empty spill areas until it is calculated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FredApps
left a comment
There was a problem hiding this comment.
ReviewerA — source-read COMMENT (not an approval)
I read the head of the diff: calculation opens without recalculating (file.open {recalculate: false}) and honours manual calculation mode. The workbook shows the results stored in the file (a TODAY() keeps its saved value), and the doc comment of the recalculation changes accordingly. Excel opens in manual calculation mode without recalculating and shows saved values, so the oracle matches; a read-only viewer benefits. The safety point is to make sure the user knows values may be stale (Excel shows "Calculate" in the status bar), and that a saved value of a volatile function is not presented as current. It is related to gridcraft#2308 (calculate only missing results), and the two should be consistent. I have not run it, and no exact-head CI result exists for this head. Nothing was run.
I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.
Status: waiting_author.
|
I independently implemented a minimal version of this while digging into a 3.8 M-formula workbook (details in #4462): |
Summary
file.opencan open a workbook with the results stored in it instead of calculating every formula again, and a workbook saved in manual calculation mode now opens that way by default.recalculate: falsekeeps the stored results: aTODAY()keeps the date it was saved with, and array results (legacy and dynamic) show as stored.recalculate: truealways calculates..xlsxhas<calcPr fullCalcOnLoad="1">, its.xlshas anUncalcedrecord, or GridCraft couldn't keep some of its cached array results (see How).recalculated: bool; a non-booleanrecalculateis refused before the file is read. A path that is already open is switched to as it is: the result hasalreadyOpen, plusrecalculateIgnored: truewhenrecalculatewas given.view.newWindowdoesn't calculate its copy, so a second window shows the same results.Why
Some workbooks have to read exactly as they were saved (approval forms, signed reports). GridCraft recalculated every formula on open, so volatile functions showed the day the file was viewed and any difference between calculation engines showed up as changed numbers; the workbook's manual calculation mode wasn't taken into account on open either.
Behaviour change
.xlsx(or.xls) that doesn't ask for a full calculation on load now opens with its stored results by default; withfullCalcOnLoad(.xls:Uncalced) it is calculated as before. Automatic-mode workbooks are unchanged.file.openwithoutrecalculate: the desktop and web UI (File › Open, recent files, files opened from the OS), the CLI (run --in,convert,eval --in,cat,info,mcp --in), MCPopen_workbook, and the control channel'sapp.open.How
CalcSettings::full_calc_on_load(#[serde(default)]): the stored results are out of date or incomplete.Calc::recalc_allclears it; the XLSX writer writesfullCalcOnLoadwhile it is set (and, as before, when a formula has no cached result). XLSX readscalcPr fullCalcOnLoad; XLS mapsUncalced(0x005E) to it.Sheet::spill/spill_ranges) rather than as cell contents. Opening with recalculation is unchanged:recalc_allclears the spill state and lays it out again from the formulas. A range keeps them only when it starts at its formula, holds at most 1 million cells (what the writer caches for one range; the constant is now shared) and fits in 4 million cells per workbook. Otherwise they are dropped as before and the workbook is markedfull_calc_on_load, so a manual-mode workbook opens calculated and saving asks the next reader to calculate.DocState::with_recalc(wb, path, title, recalculate); withfalsethe dependency graph is still built.After opening with stored results
TODAY(),NOW(),RAND()…),INDIRECT,OFFSET, and formulas that use names (defined names,LET/LAMBDAvariables), table references or unknown functions. The first edit can change those from their stored results even when it is unrelated to them.Limitations / follow-ups
recalculateyet: the desktop/web Open dialog and recent files, the password prompt that reopens an encrypted workbook, the control channel'sapp.open, and MCPopen_workbook(execute_commandwithfile.openreaches it).Tests
cargo xtask cisteps, run one by one: fmt, clippy (--workspace --all-targets -D warnings, allowing onlycollapsible_matchandnonminimal_bool, which the local Rust 1.95 clippy reports in untouchedgridcraft-xlsxcode),cargo test --workspace(1614 passed), assets, layers, wasm, parity, keytips.Related
recalc_allclears and lays it out again as before.🤖 Generated with Claude Code