[1] | 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 1.8.0, 2014-03-02 |
---|
| 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 | } |
---|
| 61 | |
---|
| 62 | // Set value explicit |
---|
| 63 | $cell->setValueExplicit( $value, self::dataTypeForValue($value) ); |
---|
| 64 | |
---|
| 65 | // Done! |
---|
| 66 | return TRUE; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * DataType for value |
---|
| 71 | * |
---|
| 72 | * @param mixed $pValue |
---|
| 73 | * @return string |
---|
| 74 | */ |
---|
| 75 | public static function dataTypeForValue($pValue = null) { |
---|
| 76 | // Match the value against a few data types |
---|
| 77 | if (is_null($pValue)) { |
---|
| 78 | return PHPExcel_Cell_DataType::TYPE_NULL; |
---|
| 79 | |
---|
| 80 | } elseif ($pValue === '') { |
---|
| 81 | return PHPExcel_Cell_DataType::TYPE_STRING; |
---|
| 82 | |
---|
| 83 | } elseif ($pValue instanceof PHPExcel_RichText) { |
---|
| 84 | return PHPExcel_Cell_DataType::TYPE_INLINE; |
---|
| 85 | |
---|
| 86 | } elseif ($pValue{0} === '=' && strlen($pValue) > 1) { |
---|
| 87 | return PHPExcel_Cell_DataType::TYPE_FORMULA; |
---|
| 88 | |
---|
| 89 | } elseif (is_bool($pValue)) { |
---|
| 90 | return PHPExcel_Cell_DataType::TYPE_BOOL; |
---|
| 91 | |
---|
| 92 | } elseif (is_float($pValue) || is_int($pValue)) { |
---|
| 93 | return PHPExcel_Cell_DataType::TYPE_NUMERIC; |
---|
| 94 | |
---|
| 95 | } elseif (preg_match('/^\-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)$/', $pValue)) { |
---|
| 96 | return PHPExcel_Cell_DataType::TYPE_NUMERIC; |
---|
| 97 | |
---|
| 98 | } elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) { |
---|
| 99 | return PHPExcel_Cell_DataType::TYPE_ERROR; |
---|
| 100 | |
---|
| 101 | } else { |
---|
| 102 | return PHPExcel_Cell_DataType::TYPE_STRING; |
---|
| 103 | |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | } |
---|