PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

Grouped images are not preserved when reading and writing xlsx files

Open rpg600 opened this issue 4 months ago • 2 comments

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

Image

test file

group_issue.xlsx

Xml file comparison

original_drawing.xml

generated_drawing.xml

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)

rpg600 avatar Nov 06 '25 11:11 rpg600

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 avatar Nov 06 '25 15:11 oleibman

@oleibman Yes, as long as the image position stays the same.

rpg600 avatar Nov 06 '25 16:11 rpg600

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.

oleibman avatar Dec 13 '25 18:12 oleibman

Now that your PR is merged, do you want to keep this issue open?

oleibman avatar Dec 14 '25 09:12 oleibman