feat(document): read the number and the formula a sheet cell holds - #853
Open
andiwand wants to merge 1 commit into
Open
feat(document): read the number and the formula a sheet cell holds#853andiwand wants to merge 1 commit into
andiwand wants to merge 1 commit into
Conversation
`SheetCell::value()` answers what a cell holds past the text it shows: the number the file states, and the formula behind a cached result. The text is not repeated - it stays in the cell's children, where it is read from. odf reads `office:value` and `table:formula`, ooxml `<v>` and `<f>`, csv the field it already types. `xls` and `numbers` keep only display strings at parse time, so they answer with the type alone. `value_type` is unchanged and stays the question the renderer asks of every cell, which is the cheaper one. A shared ooxml formula writes its expression on the group's master, so a member's formula is set and empty rather than absent; `sample.xlsx` has both kinds. `util::number::parse` is the locale-independent decimal parse this wanted: `std::strtod` reads `LC_NUMERIC` and would truncate `1234.5` to `1234` on a german host, and `std::from_chars` for double is not in libc++ 18. This is the first step of `docs/design/spreadsheet-editing.md`, the staged plan for spreadsheet editing that lands with it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F17g1P9PbwFVspTzMSBqiQ
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.
🤖 Generated with Claude Code
Step 0.1 of spreadsheet editing, plus the plan it is the first step of.
The plan
docs/design/spreadsheet-editing.mdstages the work from "type a number into acell" to a formula engine, and records why each decision went the way it did.
The load-bearing ones:
often has no element — every empty cell in both formats, every repeated cell
in ODS — so an id cannot name it. Ids stay right for text documents, where an
insertion point inside a paragraph has no position of its own.
you may not type text" is a rule no spreadsheet has and neither file format
has either. A strict grammar decides number vs. string, a leading
'forcesstring, and both the value and its string are written.
and no
contenteditableon a cell — atdholds wrappers and shapes, so theeditor is an overlay. The page carries only lock classes on the cells that
cannot be edited.
odr.onEditRefused, soa mobile host can put it in a snackbar. The host owns the wording — nothing
here is localised — and the page de-dupes its own repeats so four taps are one
snackbar. The same channel carries the dirty flag a save button needs.
the expression tree means writing the function library twice. Shipping the
engine as wasm inside the page stays possible — it is the same C++ — but costs
an emscripten build inside every platform build, and no current host needs it.
What this PR implements
The text is not repeated in it — it stays in the cell's children, where it
is already read from.
value_type()is unchanged and stays whattranslate_sheetasks of every cell, which is the cheaper question; this PRadds nothing to the render path.
office:valuetable:formula<v>, wherec/@ttypes one<f>xlsandnumbersread every cell into its display string at parse time, soneither the number nor an expression survives to be handed out; they answer with
the type alone.
Two details worth a look:
a member's
formulais set and empty rather than absent — unset wouldclaim the cell computes nothing.
odr-public/xlsx/sample.xlsxhas both kinds,and reading it confirms the distinction is real, not theoretical.
numberis wider thantype == float_number. A percentage or a currencystates an
office:valueand is still typed a string, because the type is readfrom
office:value-typealone. Fixing that changes cell alignment and thereference output, so it belongs with number formats, later.
util::number::parseThe locale-independent decimal parse this needed.
std::strtodreadsLC_NUMERICand truncates1234.5to1234under a german host locale;std::from_charsfordoubleis not in libc++ 18, the oldest standard libraryin the profile matrix. So:
istringstreamimbued with the classic locale, strictabout trailing input. Three existing
strtodsites could move onto it later.Checks
per engine, built from inline XML — no new fixtures.
ooxml_spreadsheet_merge_test.cpphad is nowooxml_spreadsheet_test_util.hpp, used by both, since the write-side stepswill want it too.
-Wall -Wextra -Werrorover every touched TU, validated with a negativecontrol. It caught two
{.type = …}designated initialisers that AppleClang ishappy with and gcc is not — they are plain assignments now.
derived-method-shadowing-base-methodones on untouched public headers.Not in this PR
The rest of step 0: the write hook, xlsx
save, the op envelope replacingmodifiedText, and the capability rows. Thecontenteditablegate is deliberatelyseparate — it changes the reference output — and the plan now says so, having
originally told itself to gate on
is_editable, which the same step makes true.