Skip to content

Commit fa51a85

Browse files
authored
Fix XLSX reader when having a corrupt numeric cell data type (#1664)
* fix for read xlsx with somewhat corrupt cell data type
1 parent d28b7de commit fa51a85

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
128128
- Reader/Gnumeric Failure with PHP8 [#1662](https://github.com/phpoffice/phpspreadsheet/pull/1662)
129129
- ReverseSort bug, exposed but not caused by PHP8 [#1660](https://github.com/phpoffice/phpspreadsheet/pull/1660)
130130
- Bug setting Superscript/Subscript to false [#1567](https://github.com/phpoffice/phpspreadsheet/pull/1567)
131+
- Fix XLSX reader when having a corrupt numeric cell data type [#1664](https://github.com/phpoffice/phpspreadsheet/pull/1664)
131132

132133
## 1.14.1 - 2020-07-19
133134

@@ -656,4 +657,4 @@ For a comprehensive list of all class changes, and a semi-automated migration pa
656657

657658
## Previous versions of PHPExcel
658659

659-
The changelog for the project when it was called PHPExcel is [still available](./CHANGELOG.PHPExcel.md).
660+
The changelog for the project when it was called PHPExcel is [still available](./CHANGELOG.PHPExcel.md).

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PhpOffice\PhpSpreadsheet\Reader;
44

55
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
6+
use PhpOffice\PhpSpreadsheet\Cell\DataType;
67
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink;
78
use PhpOffice\PhpSpreadsheet\DefinedName;
89
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
@@ -735,6 +736,10 @@ public function load($pFilename)
735736
$cell = $docSheet->getCell($r);
736737
// Assign value
737738
if ($cellDataType != '') {
739+
// it is possible, that datatype is numeric but with an empty string, which result in an error
740+
if ($cellDataType === DataType::TYPE_NUMERIC && $value === '') {
741+
$cellDataType = DataType::TYPE_STRING;
742+
}
738743
$cell->setValueExplicit($value, $cellDataType);
739744
} else {
740745
$cell->setValue($value);

0 commit comments

Comments
 (0)