From 752aeacfc735711861530ae0273f3344dc31726f Mon Sep 17 00:00:00 2001 From: jarrett jordaan Date: Mon, 29 Mar 2021 15:28:17 +0200 Subject: [PATCH 1/5] Update Xlsx.php When loading an xlsx file which has images that use a URL, there's a PHP Notice that is shown. Added a check for the existence of the array key for accessing. --- src/PhpSpreadsheet/Reader/Xlsx.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 219a49fb7d..cebe831c19 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1199,14 +1199,17 @@ public function load($pFilename) $objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); $objDrawing->setName((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); $objDrawing->setDescription((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); - $objDrawing->setPath( - 'zip://' . File::realpath($pFilename) . '#' . - $images[(string) self::getArrayItem( - $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), - 'embed' - )], - false + $imageKey = (string) self::getArrayItem( + $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), + 'embed' ); + if (isset($images[$imageKey])) { + $objDrawing->setPath( + 'zip://' . File::realpath($pFilename) . '#' . + $images[$imageKey], + false + ); + } $objDrawing->setCoordinates(Coordinate::stringFromColumnIndex(((string) $twoCellAnchor->from->col) + 1) . ($twoCellAnchor->from->row + 1)); $objDrawing->setOffsetX(Drawing::EMUToPixels($twoCellAnchor->from->colOff)); $objDrawing->setOffsetY(Drawing::EMUToPixels($twoCellAnchor->from->rowOff)); From 832e09454318440a0d6e7acbf393f9ee3c76e7c5 Mon Sep 17 00:00:00 2001 From: jarrett jordaan Date: Mon, 29 Mar 2021 15:50:54 +0200 Subject: [PATCH 2/5] Update Xlsx.php Might as well fix the other similar reference as well. --- src/PhpSpreadsheet/Reader/Xlsx.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index cebe831c19..79bbd8c15b 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1133,14 +1133,17 @@ public function load($pFilename) $objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); $objDrawing->setName((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); $objDrawing->setDescription((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); - $objDrawing->setPath( - 'zip://' . File::realpath($pFilename) . '#' . - $images[(string) self::getArrayItem( + $imageKey = (string) self::getArrayItem( $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'embed' - )], - false - ); + ); + if (isset($images[$imageKey])) { + $objDrawing->setPath( + 'zip://' . File::realpath($pFilename) . '#' . + $images[$imageKey], + false + ); + } $objDrawing->setCoordinates(Coordinate::stringFromColumnIndex(((string) $oneCellAnchor->from->col) + 1) . ($oneCellAnchor->from->row + 1)); $objDrawing->setOffsetX(Drawing::EMUToPixels($oneCellAnchor->from->colOff)); $objDrawing->setOffsetY(Drawing::EMUToPixels($oneCellAnchor->from->rowOff)); From 2924a5ca230f25d5a0d9985017659bebb1580779 Mon Sep 17 00:00:00 2001 From: jarrett jordaan Date: Mon, 29 Mar 2021 17:01:56 +0200 Subject: [PATCH 3/5] Update Xlsx.php Fix improper indentation. --- src/PhpSpreadsheet/Reader/Xlsx.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 79bbd8c15b..4249e572af 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1134,9 +1134,9 @@ public function load($pFilename) $objDrawing->setName((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); $objDrawing->setDescription((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); $imageKey = (string) self::getArrayItem( - $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), - 'embed' - ); + $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), + 'embed' + ); if (isset($images[$imageKey])) { $objDrawing->setPath( 'zip://' . File::realpath($pFilename) . '#' . From 72d9ca9b53bca4066c89cfccf35c0faf9e182277 Mon Sep 17 00:00:00 2001 From: jarrett jordaan Date: Mon, 12 Apr 2021 14:31:33 +0200 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69d1652a2b..ae671586c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed +- Fixed issue where array key check for existince before accessing arrays in Xlsx.php. [Pr #1970] - Fixed issue with quoted strings in number format mask rendered with toFormattedString() [Issue 1972#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1972) [PR #1978](https://github.com/PHPOffice/PhpSpreadsheet/pull/1978) - Fixed issue with percentage formats in number format mask rendered with toFormattedString() [Issue 1929#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1929) [PR #1928](https://github.com/PHPOffice/PhpSpreadsheet/pull/1928) - Fixed issue with _ spacing character in number format mask corrupting output from toFormattedString() [Issue 1924#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1924) [PR #1927](https://github.com/PHPOffice/PhpSpreadsheet/pull/1927) From 6db4c9fc1a7a3250f614ec19189535662171943d Mon Sep 17 00:00:00 2001 From: jarrett jordaan Date: Mon, 12 Apr 2021 14:32:20 +0200 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae671586c9..5d53073593 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed -- Fixed issue where array key check for existince before accessing arrays in Xlsx.php. [Pr #1970] +- Fixed issue where array key check for existince before accessing arrays in Xlsx.php. [PR #1970](https://github.com/PHPOffice/PhpSpreadsheet/pull/1970) - Fixed issue with quoted strings in number format mask rendered with toFormattedString() [Issue 1972#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1972) [PR #1978](https://github.com/PHPOffice/PhpSpreadsheet/pull/1978) - Fixed issue with percentage formats in number format mask rendered with toFormattedString() [Issue 1929#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1929) [PR #1928](https://github.com/PHPOffice/PhpSpreadsheet/pull/1928) - Fixed issue with _ spacing character in number format mask corrupting output from toFormattedString() [Issue 1924#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1924) [PR #1927](https://github.com/PHPOffice/PhpSpreadsheet/pull/1927)