Skip to content

Commit

Permalink
General: Work Item PHPOfficeGH-394 - DefaultValueBinder is too much a…
Browse files Browse the repository at this point in the history
…ggressive when converting string to numeric
  • Loading branch information
MarkBaker committed Sep 9, 2014
1 parent 31d60ad commit d4a641c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
16 changes: 5 additions & 11 deletions Classes/PHPExcel/Cell/DefaultValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,25 @@ public static function dataTypeForValue($pValue = null) {
// Match the value against a few data types
if (is_null($pValue)) {
return PHPExcel_Cell_DataType::TYPE_NULL;

} elseif ($pValue === '') {
return PHPExcel_Cell_DataType::TYPE_STRING;

} elseif ($pValue instanceof PHPExcel_RichText) {
return PHPExcel_Cell_DataType::TYPE_INLINE;

} elseif ($pValue{0} === '=' && strlen($pValue) > 1) {
return PHPExcel_Cell_DataType::TYPE_FORMULA;

} elseif (is_bool($pValue)) {
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} !== '.' ) {
return PHPExcel_Cell_DataType::TYPE_STRING;
}
return PHPExcel_Cell_DataType::TYPE_NUMERIC;

} elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) {
return PHPExcel_Cell_DataType::TYPE_ERROR;

} else {
return PHPExcel_Cell_DataType::TYPE_STRING;

}

return PHPExcel_Cell_DataType::TYPE_STRING;
}
}
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Planned for v1.8.1
- Bugfix: (MBaker) - Fix to getStyle() call for cell object
- General: (MBaker) - Small performance improvement for autosize columns
- General: (frost-nzcr4) Work Item GH-379 - Change the getter/setter for zeroHeight to camel case
- General: (MBaker) Work Item GH-394 - DefaultValueBinder is too much aggressive when converting string to numeric
- Feature: (WiktrzGE) Work Item GH-404 - Methods to manage most of the existing options for Chart Axis, Major Grid-lines and Minor Grid-lines
- Feature: (frost-nzcr4) Work Item GH-403 - ODS read/write comments in the cell
- Feature: (CQD) Work Item GH-389 - Additional Mac CJK codepage definitions
Expand Down

0 comments on commit d4a641c

Please sign in to comment.