Skip to content

Commit

Permalink
Fix "Xlsx::getArrayItem(): Node no longer exists" issue (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
azurre authored and Mark Baker committed Apr 15, 2019
1 parent 25c7187 commit dfd9c5b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Expand Up @@ -1667,12 +1667,13 @@ public function load($pFilename)
if ($outerShdw) {
$shadow = $objDrawing->getShadow();
$shadow->setVisible(true);
$shadow->setBlurRadius(Drawing::EMUTopixels(self::getArrayItem($outerShdw->attributes(), 'blurRad')));
$shadow->setDistance(Drawing::EMUTopixels(self::getArrayItem($outerShdw->attributes(), 'dist')));
$shadow->setBlurRadius(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'blurRad')));
$shadow->setDistance(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'dist')));
$shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem($outerShdw->attributes(), 'dir')));
$shadow->setAlignment((string) self::getArrayItem($outerShdw->attributes(), 'algn'));
$shadow->getColor()->setRGB(self::getArrayItem($outerShdw->srgbClr->attributes(), 'val'));
$shadow->setAlpha(self::getArrayItem($outerShdw->srgbClr->alpha->attributes(), 'val') / 1000);
$clr = isset($outerShdw->srgbClr) ? $outerShdw->srgbClr : $outerShdw->prstClr;
$shadow->getColor()->setRGB(self::getArrayItem($clr->attributes(), 'val'));
$shadow->setAlpha(self::getArrayItem($clr->alpha->attributes(), 'val') / 1000);
}

$this->readHyperLinkDrawing($objDrawing, $oneCellAnchor, $hyperlinks);
Expand Down Expand Up @@ -1719,12 +1720,13 @@ public function load($pFilename)
if ($outerShdw) {
$shadow = $objDrawing->getShadow();
$shadow->setVisible(true);
$shadow->setBlurRadius(Drawing::EMUTopixels(self::getArrayItem($outerShdw->attributes(), 'blurRad')));
$shadow->setDistance(Drawing::EMUTopixels(self::getArrayItem($outerShdw->attributes(), 'dist')));
$shadow->setBlurRadius(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'blurRad')));
$shadow->setDistance(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'dist')));
$shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem($outerShdw->attributes(), 'dir')));
$shadow->setAlignment((string) self::getArrayItem($outerShdw->attributes(), 'algn'));
$shadow->getColor()->setRGB(self::getArrayItem($outerShdw->srgbClr->attributes(), 'val'));
$shadow->setAlpha(self::getArrayItem($outerShdw->srgbClr->alpha->attributes(), 'val') / 1000);
$clr = isset($outerShdw->srgbClr) ? $outerShdw->srgbClr : $outerShdw->prstClr;
$shadow->getColor()->setRGB(self::getArrayItem($clr->attributes(), 'val'));
$shadow->setAlpha(self::getArrayItem($clr->alpha->attributes(), 'val') / 1000);
}

$this->readHyperLinkDrawing($objDrawing, $twoCellAnchor, $hyperlinks);
Expand Down

1 comment on commit dfd9c5b

@serverdevil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the following error even with version 1.7 PhpSpreadsheet.

Seems like $clr->alpha can be null. Unfortunately, the sheet this has a problem with, I'm not at liberty to share. Do you think a similar isset($clr->alpha) is warranted?


Fatal error: Uncaught Error: Call to a member function attributes() on null in /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php:1732 Stack trace: #0 /var/www/html/NBUIExcelReader.php(57): PhpOffice\PhpSpreadsheet\Reader\Xlsx->load('/var/www/html/u...') #1 /var/www/html/NBUIExcelReader.php(92): NBUIExcelReader->loadSheetWithoutFilter() #2 /var/www/html/upload-manager.php(61): NBUIExcelReader->readFullFile() #3 {main} thrown in /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line 1732

Please sign in to comment.