From d5aea26449818ab0b6131f6fa68a31af1b9dd4e2 Mon Sep 17 00:00:00 2001 From: zura2 Date: Mon, 10 Jun 2019 17:48:31 +0400 Subject: [PATCH] fixed foreach when styles info is missing --- Classes/PHPExcel/Reader/Excel2007.php | 52 ++++++++++++++------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 1932df4b6..e8a3bce1f 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -309,7 +309,7 @@ private function getFromZipArchive($archive, $fileName = '') // Sadly, some 3rd party xlsx generators don't use consistent case for filenaming // so we need to load case-insensitively from the zip file - + // Apache POI fixes $contents = $archive->getFromIndex( $archive->locateName($fileName, ZIPARCHIVE::FL_NOCASE) @@ -545,32 +545,36 @@ public function load($pFilename) $excel->addCellXf($objStyle); } - foreach ($xmlStyles->cellStyleXfs->xf as $xf) { - $numFmt = PHPExcel_Style_NumberFormat::FORMAT_GENERAL; - if ($numFmts && $xf["numFmtId"]) { - $tmpNumFmt = self::getArrayItem($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); - if (isset($tmpNumFmt["formatCode"])) { - $numFmt = (string) $tmpNumFmt["formatCode"]; - } elseif ((int)$xf["numFmtId"] < 165) { - $numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]); + try { + foreach ($xmlStyles->cellStyleXfs->xf as $xf) { + $numFmt = PHPExcel_Style_NumberFormat::FORMAT_GENERAL; + if ($numFmts && $xf["numFmtId"]) { + $tmpNumFmt = self::getArrayItem($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); + if (isset($tmpNumFmt["formatCode"])) { + $numFmt = (string)$tmpNumFmt["formatCode"]; + } elseif ((int)$xf["numFmtId"] < 165) { + $numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]); + } } - } - $cellStyle = (object) array( - "numFmt" => $numFmt, - "font" => $xmlStyles->fonts->font[intval($xf["fontId"])], - "fill" => $xmlStyles->fills->fill[intval($xf["fillId"])], - "border" => $xmlStyles->borders->border[intval($xf["borderId"])], - "alignment" => $xf->alignment, - "protection" => $xf->protection, - "quotePrefix" => $quotePrefix, - ); - $cellStyles[] = $cellStyle; + $cellStyle = (object)array( + "numFmt" => $numFmt, + "font" => $xmlStyles->fonts->font[intval($xf["fontId"])], + "fill" => $xmlStyles->fills->fill[intval($xf["fillId"])], + "border" => $xmlStyles->borders->border[intval($xf["borderId"])], + "alignment" => $xf->alignment, + "protection" => $xf->protection, + "quotePrefix" => $quotePrefix, + ); + $cellStyles[] = $cellStyle; + + // add style to cellStyleXf collection + $objStyle = new PHPExcel_Style; + self::readStyle($objStyle, $cellStyle); + $excel->addCellStyleXf($objStyle); + } + } catch (\Exception $e) { - // add style to cellStyleXf collection - $objStyle = new PHPExcel_Style; - self::readStyle($objStyle, $cellStyle); - $excel->addCellStyleXf($objStyle); } }