From d44aebc0a41a0eb5ca4dd6965f76c1b2ee8a4e4a Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 26 Mar 2015 23:25:24 +0000 Subject: [PATCH] Improve default value binder handling of string/numeric values - Modified regexp to handle scientific notation and apply appropriate tests rather than drop through to string - modified handler to detect integers too long for PHP, and treat as string rather than convert to float --- Classes/PHPExcel/Cell/DefaultValueBinder.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Classes/PHPExcel/Cell/DefaultValueBinder.php b/Classes/PHPExcel/Cell/DefaultValueBinder.php index 59a9c71..a9dae41 100644 --- a/Classes/PHPExcel/Cell/DefaultValueBinder.php +++ b/Classes/PHPExcel/Cell/DefaultValueBinder.php @@ -86,8 +86,11 @@ class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder return PHPExcel_Cell_DataType::TYPE_BOOL; } elseif (is_float($pValue) || is_int($pValue)) { return PHPExcel_Cell_DataType::TYPE_NUMERIC; - } elseif (preg_match('/^\-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)$/', $pValue)) { - if (is_string($pValue) && $pValue{0} === '0' && strlen($pValue) > 1 && $pValue{1} !== '.' ) { + } elseif (preg_match('/^[\+\-]?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $pValue)) { + $tValue = ltrim($pValue, '+-'); + if (is_string($pValue) && $tValue{0} === '0' && strlen($tValue) > 1 && $tValue{1} !== '.' ) { + return PHPExcel_Cell_DataType::TYPE_STRING; + } elseif((strpos($pValue, '.') === false) && ($pValue > PHP_INT_MAX)) { return PHPExcel_Cell_DataType::TYPE_STRING; } return PHPExcel_Cell_DataType::TYPE_NUMERIC;