Grouped images are not preserved when reading and writing xlsx files
Issue: Grouped images are not preserved when reading and writing xlsx files
Environment
PhpSpreadsheet version: 5.2.0 (also affects earlier versions) PHP version: 8.x File format: .xlsx (Office Open XML)
Description
When loading an Excel file containing grouped images and saving it back, the images inside the group are lost.
Screenshot
test file
Xml file comparison
Xml debug
works :
<xdr:twoCellAnchor>
<xdr:pic>
<a:blip r:embed="rId1"/>
</xdr:pic>
</xdr:twoCellAnchor>
don't work :
<xdr:twoCellAnchor>
<xdr:grpSp> ← THE PROBLEM
<xdr:pic>
<a:blip r:embed="rId2"/>
</xdr:pic>
<xdr:pic>
<a:blip r:embed="rId3"/>
</xdr:pic>
</xdr:grpSp>
</xdr:twoCellAnchor>
What happens
1) Reader/Xlsx.php (~line 1489)
Parses <xdr:pic> elements directly under <xdr:twoCellAnchor>
Does NOT parse <xdr:pic> inside <xdr:grpSp>
Grouped images are never loaded into DrawingCollection
2) Writer/Xlsx/Drawing.php
Regenerates Drawing XML from DrawingCollection only
Grouped images are not in the collection
Result: Grouped images omitted from output
Workaround:
Manually ungroup all images before processing (not always possible)
Solutions :
Option 1: Full Group Support (complex)
Option 2: Append the unsupported xml elements (pass-through)
Agreed - we do not yet handle grouped images. It looks like it could be very difficult to add them. Would it be useful to you if the reader processed the grouped images as individual images, so that you would lose the groupings but not the images? This would still be difficult to implement, but not as difficult as full support.
@oleibman Yes, as long as the image position stays the same.
PR #4712 adds support for grouped images. It is an opt-in feature that places restrictions on what you can do with the spreadsheet if you want to handle them, but it may be suitable for your purposes. Please let me know what you think.
Now that your PR is merged, do you want to keep this issue open?