From fa51a8590bf7d08f34ce14877605841859955bce Mon Sep 17 00:00:00 2001 From: Roland Eigelsreiter Date: Mon, 1 Feb 2021 11:56:27 +0100 Subject: [PATCH] Fix XLSX reader when having a corrupt numeric cell data type (#1664) * fix for read xlsx with somewhat corrupt cell data type --- CHANGELOG.md | 3 ++- src/PhpSpreadsheet/Reader/Xlsx.php | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c0f089a91..4c6a3fefa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,6 +128,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Reader/Gnumeric Failure with PHP8 [#1662](https://github.com/phpoffice/phpspreadsheet/pull/1662) - ReverseSort bug, exposed but not caused by PHP8 [#1660](https://github.com/phpoffice/phpspreadsheet/pull/1660) - Bug setting Superscript/Subscript to false [#1567](https://github.com/phpoffice/phpspreadsheet/pull/1567) +- Fix XLSX reader when having a corrupt numeric cell data type [#1664](https://github.com/phpoffice/phpspreadsheet/pull/1664) ## 1.14.1 - 2020-07-19 @@ -656,4 +657,4 @@ For a comprehensive list of all class changes, and a semi-automated migration pa ## Previous versions of PHPExcel -The changelog for the project when it was called PHPExcel is [still available](./CHANGELOG.PHPExcel.md). +The changelog for the project when it was called PHPExcel is [still available](./CHANGELOG.PHPExcel.md). \ No newline at end of file diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index c228f344c4..432e9d2a72 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Reader; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; +use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; use PhpOffice\PhpSpreadsheet\DefinedName; use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner; @@ -735,6 +736,10 @@ public function load($pFilename) $cell = $docSheet->getCell($r); // Assign value if ($cellDataType != '') { + // it is possible, that datatype is numeric but with an empty string, which result in an error + if ($cellDataType === DataType::TYPE_NUMERIC && $value === '') { + $cellDataType = DataType::TYPE_STRING; + } $cell->setValueExplicit($value, $cellDataType); } else { $cell->setValue($value);