Skip to content

Keep embedded images with spaces in their filenames - #430

Open
rayw-lab wants to merge 1 commit into
MathNya:masterfrom
rayw-lab:codex/xlsx-image-part-names
Open

rayw-lab wants to merge 1 commit into
MathNya:masterfrom
rayw-lab:codex/xlsx-image-part-names

Conversation

@rayw-lab

@rayw-lab rayw-lab commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

I picked up #280 because ordinary filenames can make an exported workbook lose its pictures in Excel. I used a real Excel open as the acceptance check and kept the change in the XLSX writer, where the image bytes and the references to them are put into the package.

The writer gives pictures whose filenames contain spaces an available internal part name and writes each relationship and its media bytes together. It uses both the filename and the image contents to keep separate images from sharing a part, even after opening a saved workbook and adding a new picture with an existing part's name. The original name remains on the drawing. After reading the file, Image::image_name() reports the internal part name, as it does for other embedded images.

Verification

  • Excel for Mac 16.115.2 prompted for repair when opening the original writer's output for my image.png. The repaired file showed a broken picture. With the patch, the workbook generated from the same input opens directly and shows the image.
  • A second workbook with my image.png, my%20image.png, and my_image.png opened in Excel after a library read and write. All three pictures displayed, and the ZIP relationship targets resolved to the expected bytes. The final patch produces the same drawing and media parts as those Excel-checked files.
  • The Rust regressions cover a collision with image1.png, adding a same-named image after reopening a generated file, and a name already used by a lazily copied sheet. A streaming check exercised both write orders. The existing aaa.xlsm fixture retained all 11 drawing, VML, and worksheet image relationships and seven media payloads.
  • cargo test --all-features passed 432 tests, including 80 doctests, with 23 ignored. Clippy with -D warnings and the nightly formatting check passed.

Fixes #280

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Images with spaces in the file name results in corrupted Excel file

1 participant