Skip to content

Grouped images are not preserved when reading and writing xlsx files #4704

@rpg600

Description

@rpg600

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions