feat(xlsx): apply plain number formats and add cell_text_mode for normalized values #5197
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.48) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 542 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.377
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #5197"
general
weight: 0.35
ShivamSharma43
The Excel backend applied a cell number format only when the format held a
$or a%. Cells with the plain built-in formats0,0.00,#,##0and#,##0.00, and with their negative-section forms (built-in 37-40, e.g.#,##0.00_);(#,##0.00)), keptstr(value). A total that Excel shows as1,234,568came out as1234567.891, and a price shown as12.50came out as12.5.This PR does two things:
1. It removes the
$/%guard in the number formatter. Plain formats now use the same parser, half-up rounding, grouping and negative/zero sections as the currency and percent formats. Formats that the parser does not support (scientific, fractions, optional digits#.##, conditions, other locale markers, quoted literals with digits) still keepstr(value).2. After review:
_format_excel_numberand_format_excel_valuereturn a(text, orig)pair.textis the normalized value,str(value), the same as with theGeneralformat.origis the value as Excel displays it. The new optionMsExcelBackendOptions.cell_text_modeselects which value becomes the cell text:-
"formatted"(default): the displayed value. Currency, percent and date cells give the same text as onmain.-
"normalized": the stored value, for all number and date formats.TableCellandRichTableCellin docling-core have noorigfield, so a table cell holds only the selected value. A cell that becomes aTextItem(treat_singleton_as_text=True, or a section label above a table) gets the selected value intextand the displayed value inorig, in both modes.This is the first gap that was reported in a comment on #4619 (thousands separator without currency). The other gaps in that comment (non-
$currency literals, zero padding) are not in this PR.Checklist:
Review evidence:
| Format | Value |
main|"formatted"(default) |"normalized"||---|---|---|---|---|
|
0| 2.5 |2.5|3|2.5||
0.00| 12.5 |12.5|12.50|12.5||
#,##0| 1234567.891 |1234567.891|1,234,568|1234567.891||
#,##0.00| 1234.5 |1234.5|1,234.50|1234.5||
#,##0_);[Red](#,##0)| -1234.5 |-1234.5|(1,235)|-1234.5||
#,##0.00_);(#,##0.00)| -1234.5 |-1234.5|(1,234.50)|-1234.5||
"$"#,##0.00| 12.5 |$12.50|$12.50|12.5||
0%| 0.125 |13%|13%|0.125||
mmm-yy| 2025-02-01 |Feb-25|Feb-25|2025-02-01 00:00:00|Document tree: only the text of the affected table cells changes. Cell positions, tables and order do not change.
Generaland text cells keep their old text in both modes.Reference data: no ground-truth file changes with the default. As a check, I set
"normalized"as the default and regenerated the XLSX ground truth: only the date column ofxlsx_02_sample_sales_data.xlsmchanged (2024-01-01 0:00:00to2024-01-01 00:00:00, 20 cells in JSON and Markdown). I did not commit that run.Tests:
test_excel_number_format_tokens_and_sectionschecks the(text, orig)pair for every case, including the new plain formats.test_xlsx_number_formats_survive_document_conversionconverts a saved workbook in both modes.test_xlsx_singleton_number_keeps_displayed_value_in_origcheckstextandorigof a singletonTextItemin both modes.docs/usage/advanced_options.md, and a short entry in the usage skill (python-sdk.md).Checks run (Windows, Python 3.12), on the pushed commit, after a merge of current
main:pytest tests/test_backend_msexcel.py: 84 passed, 2 skipped (LibreOffice not installed).pytest tests/test_backend_msexcel.py tests/test_backend_msexcel_charts.py tests/test_backend_archive_limits.py tests/test_office_image_modes.py tests/test_backend_opendocument.py: 227 passed, 2 skipped.prek run --fileson the changed files: whitespace, license header, Ruff, Ruff format, ty and Tach passed.tach-module-coverageandmax-linescallpython3, which is not on this Windows host, so I ran both scripts directly with the venv Python: both passed.Not run: the full test suite.
🤖 Generated with Claude Code