From 75160b12821f7f4299cce7f0b69c83c1502ae071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 27 May 2024 13:08:29 +0200 Subject: 2024-02-19 upstream --- .../src/PhpSpreadsheet/Cell/DefaultValueBinder.php | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php (limited to 'vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php') diff --git a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php new file mode 100644 index 0000000..ecf466f --- /dev/null +++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php @@ -0,0 +1,82 @@ +format('Y-m-d H:i:s'); + } elseif (!($value instanceof RichText)) { + $value = (string) $value; + } + } + + // Set value explicit + $cell->setValueExplicit($value, static::dataTypeForValue($value)); + + // Done! + return true; + } + + /** + * DataType for value. + * + * @param mixed $pValue + * + * @return string + */ + public static function dataTypeForValue($pValue) + { + // Match the value against a few data types + if ($pValue === null) { + return DataType::TYPE_NULL; + } elseif (is_float($pValue) || is_int($pValue)) { + return DataType::TYPE_NUMERIC; + } elseif (is_bool($pValue)) { + return DataType::TYPE_BOOL; + } elseif ($pValue === '') { + return DataType::TYPE_STRING; + } elseif ($pValue instanceof RichText) { + return DataType::TYPE_INLINE; + } elseif (is_string($pValue) && $pValue[0] === '=' && strlen($pValue) > 1) { + return DataType::TYPE_FORMULA; + } elseif (preg_match('/^[\+\-]?(\d+\\.?\d*|\d*\\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $pValue)) { + $tValue = ltrim($pValue, '+-'); + if (is_string($pValue) && $tValue[0] === '0' && strlen($tValue) > 1 && $tValue[1] !== '.') { + return DataType::TYPE_STRING; + } elseif ((strpos($pValue, '.') === false) && ($pValue > PHP_INT_MAX)) { + return DataType::TYPE_STRING; + } elseif (!is_numeric($pValue)) { + return DataType::TYPE_STRING; + } + + return DataType::TYPE_NUMERIC; + } elseif (is_string($pValue)) { + $errorCodes = DataType::getErrorCodes(); + if (isset($errorCodes[$pValue])) { + return DataType::TYPE_ERROR; + } + } + + return DataType::TYPE_STRING; + } +} -- cgit v1.2.3