Skip to content

Commit

Permalink
fixed foreach when styles info is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
zura2 committed Jun 10, 2019
1 parent 00b4158 commit d5aea26
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions Classes/PHPExcel/Reader/Excel2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit d5aea26

Please sign in to comment.