Repository navigation
fix(xlsx): keep currency, percent, and date number formats - #4628
jipeng6036-del wants to merge 5 commits into
Conversation
Excel cells were converted with str(value) after a data_only load, so $12.50 became 12.5, 10% became 0.1, and Feb-25 became a timestamp. Apply the stored number format for currency, percentages, and dates. Custom formats still use str(value). Fixes docling-project#4619 Signed-off-by: jipeng6036-del <jipeng6036@gmail.com>
|
✅ DCO Check Passed Thanks @jipeng6036-del, all your commits are properly signed off. 🎉 |
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 Require two reviewer for test updatesWhen test data is updated, we require two reviewers
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
DanielNg0729
left a comment
There was a problem hiding this comment.
Hi @jipeng6036-del, thank you for this fix
I tried some built-in Excel formats and found a few cases where the date path now gives worse text than main.
| Format | Value | main |
this PR | Excel shows |
|---|---|---|---|---|
mm-dd-yy (built-in 14) |
2025-02-01 | 2025-02-01 00:00:00 |
02-01-25 |
2/1/2025 (en-US short date) |
mm:ss (built-in 45) |
00:07:45 | 00:07:45 |
01:45 |
07:45 |
h:mm AM/PM (built-in 18) |
13:30 | 13:30:00 |
13:30 PM |
1:30 PM |
"Due "mmm d |
2025-02-01 | 2025-02-01 00:00:00 |
01ue Feb 01 |
Due Feb 1 |
I left the details as inline comments. Please see below. Thanks.
Signed-off-by: jipeng6036-del <jipeng6036@gmail.com>
Signed-off-by: jipeng6036-del <jipeng6036@gmail.com>
|
Thanks @DanielNg0729 — the follow-up in 3513b5d addresses the cases you listed. Summary:
Also merged current Happy to adjust further if any of these should still fall back instead of rendering. |
AI triage (advisory)Checked commit Adds number-format rendering for XLSX worksheet cells so that currency, percent, and date values display as Excel would show them instead of collapsing to raw Python values. Chart data keeps raw cached values without formatting. CI safety: no concern found. A maintainer must still approve CI. 2 related pull request(s) in the same code
Reference data changes
Assessment: expected. The PR applies number formats to worksheet cells, so existing sales data cells that held raw floats and datetimes now render as formatted strings; 20 changed cells in the JSON and 20 changed rows in the Markdown are the direct result of that fix. The |
|
@DanielNg0729 can you please have another look here? |
DanielNg0729
left a comment
There was a problem hiding this comment.
Hi @jipeng6036-del, thank you for the update,
I checked again on ab177e14. All the cases from my earlier review now match Excel. The workbook attached to #4619 gives $12.50, $270.00, 10% and Feb-25. The Excel tests pass here (59 passed, 2 skipped), also after a merge with current main.
Before I approve, I would like to ask for a few more changes:
- The chart data tables now also use the number format. Could you please confirm if this is intended? (inline comment on
_resolve_reference) - The description says
Resolves #4619, so the issue closes when this PR merges. The formula part of #4619 is not in this PR. Could you change it toPart of #4619, so that the formula request stays open? - Two small clean-ups: a comment that is now in the wrong place, and an unused import (inline comments).
Inline comments
docling/backend/msexcel_backend.py L120 (the # Maps an openpyxl chart object's tagname comment)
This comment is for _CHART_TAGNAME_TO_CLASSIFICATION, but the new block is now between the comment and the dict. So it reads as the comment for _GENERAL_NUMBER_FORMATS. Could the new constants and helpers go above this comment?
docling/backend/msexcel_backend.py L91
from_excel is not used. Ruff does not report it, because this repo ignores F401. Could you remove it?
docling/backend/msexcel_backend.py L2093
This also changes the chart data tables, because _chart_to_table_data reads the categories and values through _resolve_reference. For a bar chart over "$"#,##0.00 cells, the table now shows $1,234.50 and $99.13. On main it shows 1234.5 and 99.125, so the chart data loses precision. The PPTX and Word chart tables keep the raw numbers. Is this intended? If yes, could you add a test and one line in the description? If not, maybe this path could keep str(value).
docling/backend/msexcel_backend.py L125 (optional)
mmmmm (the first letter of the month) splits into mmmm + m, so it gives February2. Excel shows F, and main gives 2025-02-01 00:00:00. Maybe add mmmmm to the tokens, or fall back for it?
docling/backend/msexcel_backend.py L280 (optional)
Excel keeps the case of the marker, so h:mm am/pm shows 1:30 pm. Here it gives 1:30 PM.
tests/test_backend_msexcel.py L1084 (optional)
The names test_excel_review_number_format_regressions and test_xlsx_review_formats_survive_document_conversion (L1088) refer to this review. Names that describe the behaviour may be clearer later. Also, the workbook formulas_and_number_formats.xlsx at L1141 has no formulas.
Signed-off-by: jipeng6036-del <jipeng6036@gmail.com>
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
|
@DanielNg0729 can you please re-check and approve again? I rebased it to current |
DanielNg0729
left a comment
There was a problem hiding this comment.
Thank you very much @cau-git, Looks good to me!
Part of #4619.
Excel table conversion discarded stored number formats after loading cached formula values. A price such as
$12.50became12.5, and10%became0.1.Apply supported currency, percent, and date formats to worksheet table cells. Preserve quoted and escaped literals, distinguish minutes from months, honor 12-hour time and the case of
AM/PM, and supportmmmmmmonth initials. Use decimal half-up rounding and the negative/zero format sections. Locale-dependent built-in short date and date-time formats use ISO values; unsupported complex formats retainstr(value).Chart data keeps the raw cached values, including categories and series names, without applying cell display formats. For example, worksheet cells show
$1,234.50and$99.13, while the reconstructed chart table retains1234.5and99.125. The conversion regression checks both tables and their cell positions.Formulas still use their cached results through
data_only=True. Formula metadata requires a separate docling-core schema change and is not addressed here.Validation for
bb39a3b96ecc94deb582965759ac24cd2fb0f973on Windows / Python 3.13.12:python -m pytest tests/test_backend_msexcel.py -q: 66 passed, 2 skipped because LibreOffice is unavailable.ab177e14before the follow-up fix.make validatechangeset recipe, run asuv run --no-sync prek run --files docling/backend/msexcel_backend.py tests/test_backend_msexcel.py, passed all applicable hooks: Ruff, ty, Tach, module coverage, max lines, and file checks. A localpython3.cmdshim points to the same venv for Windows; tracked check configuration is unchanged.git diff --check: passed.The existing sales Markdown/JSON reference updates only change date-time text for an unpadded
htoken; the JSON grid copies match. They do not change ownership or order, and still require the repository's two-reviewer approval.Hosted Run CI and Run Docs CI completed successfully on this exact commit (attempt 2). The Python 3.10 core/ML tests, lint, Tach, package checks, documentation build, DCO, and patch coverage passed. Windows/macOS and the optional install jobs were skipped. DanielNg0729 approved this commit on 2026-10-14; the test-reference changes still await the required second reviewer.