Skip to content

fix(xlsx): keep CMYK pictures instead of dropping or re-rendering them - #4664

Merged
PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
usmanmateen:fix-xlsx-cmyk-pictures
Oct 8, 2026
Merged

PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
usmanmateen:fix-xlsx-cmyk-pictures

Conversation

@usmanmateen

Copy link
Copy Markdown
Contributor

Resolves #4658

Unlike the Word and PowerPoint backends since #4598, the Excel backend didn't run normalize_image_for_png on pictures. A CMYK picture failed on both of its paths:

  • _find_images_in_sheet: ImageRef.from_pil can't write CMYK as PNG, so the picture was dropped with could not extract the image from excel sheets.
  • _process_drawing_for_unsupported_images: the PNG probe failed on the same picture, so it was treated as EMF/WMF and, when LibreOffice is available, rendered through it instead of kept as stored.

This normalizes the picture on both paths. Normalizing only the first one would return the picture twice, because the probe would still send it to LibreOffice. The probe now also catches ValueError, like the PowerPoint backend does, because the RGB conversion can raise it and that would otherwise stop the scan of the whole drawing.

Checklist:

  • Documentation has been updated, if necessary. (not needed)
  • Examples have been added, if necessary. (not needed)
  • Tests have been added, if necessary.

Review evidence:

With the reproduction from the issue:

  • Before: no picture without LibreOffice, one picture at 401×201 with LibreOffice.
  • After: one picture at 200×100 in both cases.

Tests in tests/test_office_image_modes.py:

  • test_cmyk_office_picture_without_libreoffice now also runs for xlsx, with and without an invalid ICC profile.
  • test_cmyk_xlsx_picture_is_not_rendered_by_libreoffice stands in for an installed LibreOffice by patching _convert_emf_to_pil, and checks that the picture is kept once at its stored size. With only the first path fixed, it fails with 2 pictures.

Commands run (WSL2 Ubuntu, Python 3.12):

  • pytest tests/test_office_image_modes.py: 11 passed. The 3 new xlsx cases fail on main (0 pictures, 0 pictures, 401×201).
  • pytest tests/test_backend_msexcel.py: 28 passed, 2 skipped, same as on main.
  • make validate: all hooks pass.

Not run: a real LibreOffice conversion (not installed here, so the second test patches it), and the full test suite.

Unlike the Word and PowerPoint backends since docling-project#4598, the Excel backend did
not normalize pictures before PNG serialization. A CMYK picture loaded by
openpyxl failed in ImageRef.from_pil and was dropped, and the PNG probe in
the unsupported-image scan took the same picture for an EMF/WMF image and
rendered it through LibreOffice.

Normalize the picture in both paths, so it is kept once, as stored, with or
without LibreOffice.

Resolves docling-project#4658

Signed-off-by: usmanmateen <usmanmateen255@gmail.com>
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @usmanmateen, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working xlsx issue related to xlsx backend labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit f96dfd18bf. The analysis read the diff only. It did not run code from this pull request.

The PR applies normalize_image_for_png to both image-extraction paths in the Excel backend so that CMYK pictures are converted correctly instead of being dropped or re-routed to LibreOffice. It also adds ValueError to the probe exception list and adds three targeted test cases.

Topic labels added: bug, xlsx.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#4598 merged referenced as #4598 related: PR #4598 (already merged) added normalize_image_for_png for the Word and PowerPoint backends and created the shared test file. This PR extends that fix to the Excel backend; the two PRs solve the same class of problem but in different format backends.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocking issue found

This review covers the full diff at f96dfd18bf. It read the code only. It did not run tests or code from this pull request.

The PR fixes CMYK picture handling in the Excel backend, which had two failure paths: _find_images_in_sheet dropped CMYK pictures because ImageRef.from_pil could not write CMYK as PNG, and _process_drawing_for_unsupported_images re-routed them to LibreOffice because the PNG probe also failed on CMYK. The fix applies normalize_image_for_png on both paths and adds ValueError to the probe's exception handler, mirroring the Word and PowerPoint backends. Tests are targeted and would catch both regressions.

A maintainer makes the merge decision. This review never approves the pull request.

Comment thread tests/test_office_image_modes.py Resolved
Comment thread docling/backend/msexcel_backend.py Resolved
@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 8, 2026
@usmanmateen

Copy link
Copy Markdown
Contributor Author

cc @PeterStaar-IBM since you reviewed #4598, this applies the same fix to the Excel backend. Happy to adjust anything.

@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@PeterStaar-IBM
PeterStaar-IBM merged commit 4854af7 into docling-project:main Oct 8, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working xlsx issue related to xlsx backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Excel backend still drops CMYK pictures (#4586 fixed Word and PowerPoint only)

3 participants