PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.39k stars 3.48k forks source link

[Xlsx Reader] drawning $xfrm->ext Node no longer exists #2275

Open sheronov opened 3 years ago

sheronov commented 3 years ago

This is:

- [x] a bug report

What is the expected behavior?

Successful file loading with drawnings (pasted images) for next processing.

What is the current behavior?

For some files with drawings from old versions MS Excel the library throws exception PhpOffice\PhpSpreadsheet\Reader\Xlsx::getArrayItem(): Node no longer exists because of access unexisted property $xfrm->ext

How it will be solved?

There are several solutions:

  1. Open file in new MS Excel and save it as new file. But it's unconvinient for clients. (the new MS Excel version in docProps/app.xml 16.0300 fixes this problem)

  2. Skip drawings by set read data only $xlsxReader->setReadDataOnly(true);. But I wanted process drawings too.

  3. Add checking to the xlsx reader that the property $xfrm->ext is exist or coalesce (??) operator here https://github.com/PHPOffice/PhpSpreadsheet/blob/master/src/PhpSpreadsheet/Reader/Xlsx.php#L1287 Example for the master branch:

    if ($xfrm) {
    $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($xfrm->ext ?? null), 'cx')));
    $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($xfrm->ext ?? null), 'cy')));
    $objDrawing->setRotation(Drawing::angleToDegrees(self::getArrayItem(self::getAttributes($xfrm), 'rot')));
    }

What are the steps to reproduce?

I cannot link the file with mentioned problems. It's goods price list. But I can provide some information from inner xml files.

docProps/app.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
            xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
    <Application>Microsoft Excel</Application>
     ...
    <AppVersion>12.0000</AppVersion>
</Properties>

xl/drawings/drawing1.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xdr:wsDr xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
          xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
    <xdr:twoCellAnchor>
        <xdr:from>
            <xdr:col>1</xdr:col>
            <xdr:colOff>76200</xdr:colOff>
            <xdr:row>2</xdr:row>
            <xdr:rowOff>38100</xdr:rowOff>
        </xdr:from>
        <xdr:to>
            <xdr:col>1</xdr:col>
            <xdr:colOff>5076825</xdr:colOff>
            <xdr:row>3</xdr:row>
            <xdr:rowOff>0</xdr:rowOff>
        </xdr:to>
        <xdr:pic>
            <xdr:nvPicPr>
                <xdr:cNvPr name="2" descr="" id="2">
                    <a:extLst>
                        <a:ext uri="{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}"/>
                    </a:extLst>
                </xdr:cNvPr>
                <xdr:cNvPicPr>
                    <a:picLocks noChangeAspect="1"/>
                </xdr:cNvPicPr>
            </xdr:nvPicPr>
            <xdr:blipFill>
                <a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId1"/>
                <a:stretch>
                    <a:fillRect/>
                </a:stretch>
            </xdr:blipFill>
            <xdr:spPr>
                <a:xfrm rot="0"/>
                <a:prstGeom prst="rect">
                    <a:avLst/>
                </a:prstGeom>
            </xdr:spPr>
        </xdr:pic>
        <xdr:clientData/>
    </xdr:twoCellAnchor>
    ...
</xdr:wsDr>

As you can see there is an empty node <a:xfrm rot="0"/>. Here http://officeopenxml.com/drwSp-size.php (and on other pages) is not written that off and ext nodes are mandatory children in xfrm node, and vice versa - no.

Which versions of PhpSpreadsheet and PHP are affected?

Version 1.18.0 and master branch

I can create pull request. If you need more information, please let me know.

NeiroNext commented 2 years ago

Thanks for help! I also get this error and try update library to new version, but problem still doesnt fix :c But your info very an very help me))) Thank you!!!