Skip to content

fix: read self-closing a:prstGeom in drawing shape properties - #428

Open
jayhemnani9910 wants to merge 2 commits into
MathNya:masterfrom
jayhemnani9910:fix/self-closing-prstgeom
Open

jayhemnani9910 wants to merge 2 commits into
MathNya:masterfrom
jayhemnani9910:fix/self-closing-prstgeom

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

openpyxl writes a picture's geometry as a self-closing element, <a:prstGeom prst="rect" /> (ws.add_image). ShapeProperties::set_attributes handles a:prstGeom only in the Event::Start arm. The self-closing form arrives as Event::Empty, so prst stays empty and is written back as <a:prstGeom prst=""><a:avLst/></a:prstGeom>. openpyxl then refuses to open the saved file:

ValueError: Unable to read workbook: could not read worksheets ... Value must be one of {... 'rect' ...}

So reading and saving an openpyxl or pandas report that has a logo or other picture produces a file Python can no longer read. Excel writes the element with an explicit end tag and isn't affected.

The Event::Empty arm now also reads prst from a self-closing a:prstGeom, next to the existing a:noFill case.

Testing: added tests/self_closing_preset_geometry.rs with a small openpyxl-made workbook (tests/test_files/openpyxl_image.xlsx). It reads and writes the file and checks that the drawing keeps prst="rect". It fails on master and passes with the change. cargo test passes (413). Read and wrote the openpyxl file with the change, and openpyxl 3.1.5 loads the result.

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.

1 participant