From cd151ae2e4342f94f11f6b9e727c7cf1f149d15c Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Wed, 14 Oct 2015 23:23:19 +0100 Subject: [PATCH] Fix for problem with xlsx files overriding the reserved number format codes below 164 with custom codes --- Classes/PHPExcel/Reader/Excel2007.php | 3 +-- Classes/PHPExcel/Style/NumberFormat.php | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 0303a0b..5ab5a42 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -500,7 +500,6 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE if (!$this->readDataOnly && $xmlStyles) { foreach ($xmlStyles->cellXfs->xf as $xf) { $numFmt = PHPExcel_Style_NumberFormat::FORMAT_GENERAL; - if ($xf["numFmtId"]) { if (isset($numFmts)) { $tmpNumFmt = self::getArrayItem($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); @@ -513,7 +512,7 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE // We shouldn't override any of the built-in MS Excel values (values below id 164) // But there's a lot of naughty homebrew xlsx writers that do use "reserved" id values that aren't actually used // So we make allowance for them rather than lose formatting masks - if ((int)$xf["numFmtId"] < 164 && PHPExcel_Style_NumberFormat::builtInFormatCodeIndex((int)$xf["numFmtId"]) !== false) { + if ((int)$xf["numFmtId"] < 164 && PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]) !== '') { $numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]); } } diff --git a/Classes/PHPExcel/Style/NumberFormat.php b/Classes/PHPExcel/Style/NumberFormat.php index f517df3..1b72cda 100644 --- a/Classes/PHPExcel/Style/NumberFormat.php +++ b/Classes/PHPExcel/Style/NumberFormat.php @@ -338,7 +338,6 @@ class PHPExcel_Style_NumberFormat extends PHPExcel_Style_Supervisor implements P // Ensure built-in format codes are available self::fillBuiltInFormatCodes(); - // Lookup format code if (isset(self::$builtInFormats[$pIndex])) { return self::$builtInFormats[$pIndex];