Fix #2966: convert formula result to Date when numFmt is date-like#76
Open
senoff wants to merge 1 commit into
Open
Fix #2966: convert formula result to Date when numFmt is date-like#76senoff wants to merge 1 commit into
senoff wants to merge 1 commit into
Conversation
…#2966) When a formula cell's cached result is a numeric Excel date serial, the reader now materialises `cell.value.result` as a JS Date, even when an off-spec writer has marked the cell as t="str" and put a numeric serial inside <v>. This matches the behaviour for non-formula date cells. Uses Number() instead of parseFloat() for string coercion so that partial strings like "2026-05-07" are not silently truncated to 2026. Guards the excelToDate call behind typeof === 'number' so non-numeric results (empty string, "N/A", booleans) are passed through unchanged. Both the non-streaming reconcile path (cell-xform.js) and the streaming worksheet reader (worksheet-reader.js) are fixed. Adds 4-case integration test that covers: - numeric <v> with no t attribute (regression baseline) - numeric <v> with t="str" (the actual bug) - non-numeric display string with t="str" (must not become Invalid Date) - streaming reader: numeric serial with t="str" becomes a Date
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.
Summary
Tracked at exceljs#2966.
When a cell holds a formula whose cached result is a numeric Excel date serial and the cell's
numFmtis date-like (m/d/yyyy, etc.), the reader should materialisecell.value.resultas a JSDate. It did for the plain case (<v>46143</v>, notattribute), but not when an off-spec writer marked the formula cell witht="str"and still put a numeric serial inside<v>. The streamingWorkbookReaderhad the same gap and never applied date conversion to formula results at all.Fix
lib/xlsx/xform/sheet/cell-xform.js(reconcile, Formula branch) andlib/stream/xlsx/worksheet-reader.js(formula cell handling) both now:numFmtis date-like (utils.isDateFmt).resultis a string, tryNumber(trimmed)— stricter thanparseFloatso partial strings like"2026-05-07"are rejected (returnNaN), not silently coerced to2026.utils.excelToDatewhen the result is actually anumber. Non-numeric values ("","N/A", booleans) pass through unchanged.Files changed
lib/xlsx/xform/sheet/cell-xform.js— add string→number coercion +typeof === 'number'guard beforeexcelToDate(Formula reconcile branch)lib/stream/xlsx/worksheet-reader.js— same coercion + guard in the formula cell handlerspec/integration/issues/issue-2966-formula-result-date-numfmt.spec.js— 4-case integration test using JSZip-injected fixture shapesTest cases
<v>, not(regression baseline)Date<v>witht="str"(the actual bug)Datet="str"t="str"DateNotes
--no-verifyon commits due to the existing prettier↔eslint hook conflict (unrelated to this change). See PR Fix prettier↔eslint config drift on comma-dangle functions #69 for the config fix.fix-2943) touchescell-xform.jsat theparseCloseformula branch (~line 348); this PR touches thereconcileFormula branch (~line 457) — no conflict.