This closes #2307, add RecalcCell to persist a single formula cell's cached value#2311
Open
krystophny wants to merge 2 commits into
Open
This closes #2307, add RecalcCell to persist a single formula cell's cached value#2311krystophny wants to merge 2 commits into
krystophny wants to merge 2 commits into
Conversation
CalcCellValue returns a formatted string but does not touch the stored workbook. Every SetCell* writer strips the <f> element, so callers that need to refresh the cached value of a formula cell without losing the formula currently have no path. Readers that honour <v> without recomputing (LibreOffice headless, Numbers, etc.) therefore see stale numbers after any excelize round trip. Add (*File).RecalcCell(sheet, cell string) error. It evaluates the formula via the existing recursive calc engine, then writes the typed result into <v>/<t> through a private setCellCachedValue helper that leaves <f>, the shared-formula master, ref span, and si index intact. A new sentinel ErrCellNoFormula is returned when the target cell has no formula. Dependency resolution reuses calcCellValue, so chained formulas across cells converge in one pass; circular references are bounded by the workbook's existing MaxCalcIterations option. Signed-off-by: Christopher Albert <albert@tugraz.at>
This was referenced Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
(*File).RecalcCell(sheet, cell string) error. It evaluates the formula in the given cell via the existing recursive calc engine, then writes the typed result into<v>/<t>through a privatesetCellCachedValuehelper that leaves<f>, the shared-formula master,refspan, andsiindex intact. A new sentinelErrCellNoFormulais returned when the target cell has no formula.Public surface introduced by this PR:
(*File).RecalcCell(sheet, cell string) errorErrCellNoFormulaNo existing API is changed or removed.
Related Issue
Closes #2307. Companion to the umbrella #2303; the whole-workbook
File.Recalcentry point built on top ofRecalcCellwill arrive in a separate PR once this lands.Documentation
Reference-site entries for this PR ship in a companion docs PR: xuri/excelize-doc#31. That PR covers the English version; other language versions follow the project's usual rollout cadence.
Motivation and Context
CalcCellValuereturns a formatted string but does not persist it, and everySetCell*writer strips the formula while writing a new value, which makes them useless for this purpose. Downstream readers that honour<v>without recomputing (LibreOffice headless, Numbers) therefore see stale results after a round trip through excelize.RecalcCellis the smallest primitive that closes that gap; it has zero cost to callers who do not use it.Design notes reviewers are likely to ask about:
calcCellValuealready recurses into referenced cells during evaluation, so one call converges a chain.f.options.MaxCalcIterations, the same option that governs the existing calc engine. No new knob.TestRecalcCellCircularReferenceBoundedlocks termination.setCellCachedValuetouches only<v>and<t>;<f>with itst="shared",ref, andsiattributes is left untouched, and sibling children in the same band are not modified by a write to the master or another child.TestRecalcCellSharedFormulaBandlocks this.t="s"regression guard.TestRecalcCellNoTypeSRegressionpins the behaviour that motivated this work: numeric results must be stored with an implicittattribute, not as a shared string, or downstream aggregates silently sum to 0.How Has This Been Tested
Full suite:
go test -skip TestZip64 -timeout 10m .passes cleanly.gofmt -s -l .andgo vet ./...are clean. ARM cross-builds (GOARM=5|6|7,arm64,android/arm64) all build.Types of changes
Checklist
Documentation for the new exported surface lives in the doc comments on
RecalcCellandErrCellNoFormula.