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