Skip to content

Keep the type of a cached formula result through a save - #8

Merged
almasumdev merged 2 commits into
almasumdev:mainfrom
cdeil:formula-cache-type
Oct 16, 2026
Merged

almasumdev merged 2 commits into
almasumdev:mainfrom
cdeil:formula-cache-type

Conversation

@cdeil

@cdeil cdeil commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Problem. A formula cell read from a file as t="str", t="b", t="e"
(or t="d") keeps its cached <v> but not its type, so a read-and-save turns

<c r="A1" t="str"><f>"hello"</f><v>hello</v></c>

into a cell with no t and <v>hello</v>. OOXML reads an untyped cell as
numeric, so other consumers reject the file: openpyxl
load_workbook(..., data_only=True) raises
ValueError: could not convert string to float: 'hello', and an error cache
fails on '#DIV/0!'; a boolean cache silently becomes the number 1. The
library's own reader accepts the malformed cell, which is why a same-library
round trip does not show it.

Fix. The shared cell decoder (used by the eager and the streaming reader)
now carries the cell's t into the formula's cached-result type, the way
recalculate() already does; the writer already emitted that type.
_cachedTypeCode learns 'd' for ISO-date caches. The public constructor's
numeric-cache behavior is documented and unchanged; this fix does not infer
a type for a caller-supplied string.

Validation. test/formula_test.dart: four typed cases save with
their t and re-read with the same formula and cached value, plus a streamed
cell re-inserted through updateCell. All fail before, pass after.
Independent check: the saved text and error workbooks that openpyxl refused
now load with data_only=True and yield 'hello' (type s) and '#DIV/0!'
(type e). LibreOffice also opens and re-saves both workbooks, with the
cached results confirmed afterward. Full suite and analyzer clean.

🤖 Generated with Claude Code

cdeil and others added 2 commits October 16, 2026 14:35
A formula cell read from a file with t="str", t="b", t="e" or t="d"
kept its cached <v> but not the type, so a save wrote <v>hello</v> with
no t attribute. OOXML reads such a cell as numeric, and other readers
reject the file (openpyxl: could not convert string to float: 'hello').
The shared cell decoder now carries the cell's t into the formula's
cached-result type, which the writer already emits; recalculate() set
that type the same way.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@almasumdev
almasumdev merged commit 5090d51 into almasumdev:main Oct 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants