← Back to Pull requests

feat(xlsx): apply plain number formats and add cell_text_mode for normalized values #5197

Open
unknown opened this pull request with 542 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 05, 2026 12:45 UTC
Author

The Excel backend applied a cell number format only when the format held a $ or a %. Cells with the plain built-in formats 0, 0.00, #,##0 and #,##0.00, and with their negative-section forms (built-in 37-40, e.g. #,##0.00_);(#,##0.00)), kept str(value). A total that Excel shows as 1,234,568 came out as 1234567.891, and a price shown as 12.50 came out as 12.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 keep str(value).
2. After review: _format_excel_number and _format_excel_value return a (text, orig) pair. text is the normalized value, str(value), the same as with the General format. orig is the value as Excel displays it. The new option MsExcelBackendOptions.cell_text_mode selects which value becomes the cell text:
- "formatted" (default): the displayed value. Currency, percent and date cells give the same text as on main.
- "normalized": the stored value, for all number and date formats.

TableCell and RichTableCell in docling-core have no orig field, so a table cell holds only the selected value. A cell that becomes a TextItem (treat_singleton_as_text=True, or a section label above a table) gets the selected value in text and the displayed value in orig, 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:

  • Documentation has been updated, if necessary.

  • Examples have been added, if necessary.

  • Tests have been added, if necessary.
  • 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. General and 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 of xlsx_02_sample_sales_data.xlsm changed (2024-01-01 0:00:00 to 2024-01-01 00:00:00, 20 cells in JSON and Markdown). I did not commit that run.

    Tests:

  • test_excel_number_format_tokens_and_sections checks the (text, orig) pair for every case, including the new plain formats.

  • test_xlsx_number_formats_survive_document_conversion converts a saved workbook in both modes.

  • test_xlsx_singleton_number_keeps_displayed_value_in_orig checks text and orig of a singleton TextItem in both modes.

  • Docs: a section "Excel number formats" in 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 --files on the changed files: whitespace, license header, Ruff, Ruff format, ty and Tach passed. tach-module-coverage and max-lines call python3, 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

    Diff: 542 lines (+406 / -136) across 6 files Reviewer: ShivamSharma43 Review duration: 24956m
    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
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.0% (MEDIUM) · Higher = larger blast radius
    48.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.6% · Safe to merge
    25.6%