PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.0.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.0.3
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpexcel / Classes / PHPExcel / Cell / DefaultValueBinder.php

DefaultValueBinder.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.0.3, at vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell/DefaultValueBinder.php

111 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2014 PHPExcel
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 * @category PHPExcel
22 * @package PHPExcel_Cell
23 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
26 */
27
28
29 /** PHPExcel root directory */
30 if (!defined('PHPEXCEL_ROOT')) {
31 /**
32 * @ignore
33 */
34 define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36 }
37
38
39 /**
40 * PHPExcel_Cell_DefaultValueBinder
41 *
42 * @category PHPExcel
43 * @package PHPExcel_Cell
44 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
45 */
46 class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
47 {
48 /**
49 * Bind value to a cell
50 *
51 * @param PHPExcel_Cell $cell Cell to bind value to
52 * @param mixed $value Value to bind in cell
53 * @return boolean
54 */
55 public function bindValue(PHPExcel_Cell $cell, $value = null)
56 {
57 // sanitize UTF-8 strings
58 if (is_string($value)) {
59 $value = PHPExcel_Shared_String::SanitizeUTF8($value);
60 } elseif (is_object($value)) {
61 // Handle any objects that might be injected
62 if ($value instanceof DateTime) {
63 $value = $value->format('Y-m-d H:i:s');
64 } elseif (!($value instanceof PHPExcel_RichText)) {
65 $value = (string) $value;
66 }
67 }
68
69 // Set value explicit
70 $cell->setValueExplicit( $value, self::dataTypeForValue($value) );
71
72 // Done!
73 return true;
74 }
75
76 /**
77 * DataType for value
78 *
79 * @param mixed $pValue
80 * @return string
81 */
82 public static function dataTypeForValue($pValue = null) {
83 // Match the value against a few data types
84 if ($pValue === null) {
85 return PHPExcel_Cell_DataType::TYPE_NULL;
86 } elseif ($pValue === '') {
87 return PHPExcel_Cell_DataType::TYPE_STRING;
88 } elseif ($pValue instanceof PHPExcel_RichText) {
89 return PHPExcel_Cell_DataType::TYPE_INLINE;
90 } elseif ($pValue{0} === '=' && strlen($pValue) > 1) {
91 return PHPExcel_Cell_DataType::TYPE_FORMULA;
92 } elseif (is_bool($pValue)) {
93 return PHPExcel_Cell_DataType::TYPE_BOOL;
94 } elseif (is_float($pValue) || is_int($pValue)) {
95 return PHPExcel_Cell_DataType::TYPE_NUMERIC;
96 } elseif (preg_match('/^[\+\-]?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $pValue)) {
97 $tValue = ltrim($pValue, '+-');
98 if (is_string($pValue) && $tValue{0} === '0' && strlen($tValue) > 1 && $tValue{1} !== '.' ) {
99 return PHPExcel_Cell_DataType::TYPE_STRING;
100 } elseif((strpos($pValue, '.') === false) && ($pValue > PHP_INT_MAX)) {
101 return PHPExcel_Cell_DataType::TYPE_STRING;
102 }
103 return PHPExcel_Cell_DataType::TYPE_NUMERIC;
104 } elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) {
105 return PHPExcel_Cell_DataType::TYPE_ERROR;
106 }
107
108 return PHPExcel_Cell_DataType::TYPE_STRING;
109 }
110 }
111