PHPExcel_Cell
[ class tree: PHPExcel_Cell ] [ index: PHPExcel_Cell ] [ all elements ]

Source for file DefaultValueBinder.php

Documentation is available at DefaultValueBinder.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2010 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 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.3c, 2010-06-01
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Cell_DefaultValueBinder
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_Cell
  34.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36. class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
  37. {
  38.     /**
  39.      * Bind value to a cell
  40.      *
  41.      * @param PHPExcel_Cell $cell    Cell to bind value to
  42.      * @param mixed $value            Value to bind in cell
  43.      * @return boolean 
  44.      */
  45.     public function bindValue(PHPExcel_Cell $cell$value null)
  46.     {
  47.         // sanitize UTF-8 strings
  48.         if (is_string($value)) {
  49.             $value PHPExcel_Shared_String::SanitizeUTF8($value);
  50.         }
  51.  
  52.         // Set value explicit
  53.         $cell->setValueExplicit$valuePHPExcel_Cell_DataType::dataTypeForValue($value) );
  54.  
  55.         // Done!
  56.         return true;
  57.     }
  58.  
  59.     /**
  60.      * DataType for value
  61.      *
  62.      * @param    mixed     $pValue 
  63.      * @return     int 
  64.      */
  65.     public static function dataTypeForValue($pValue null{
  66.         // Match the value against a few data types
  67.         if (is_null($pValue)) {
  68.             return PHPExcel_Cell_DataType::TYPE_NULL;
  69.  
  70.         elseif ($pValue === ''{
  71.             return PHPExcel_Cell_DataType::TYPE_STRING;
  72.  
  73.         elseif ($pValue instanceof PHPExcel_RichText{
  74.             return PHPExcel_Cell_DataType::TYPE_STRING;
  75.  
  76.         elseif ($pValue{0=== '=' && strlen($pValue1{
  77.             return PHPExcel_Cell_DataType::TYPE_FORMULA;
  78.  
  79.         elseif (is_bool($pValue)) {
  80.             return PHPExcel_Cell_DataType::TYPE_BOOL;
  81.  
  82.         elseif (is_float($pValue|| is_int($pValue)) {
  83.             return PHPExcel_Cell_DataType::TYPE_NUMERIC;
  84.  
  85.         elseif (preg_match('/^\-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)$/'$pValue)) {
  86.             return PHPExcel_Cell_DataType::TYPE_NUMERIC;
  87.  
  88.         elseif (is_string($pValue&& array_key_exists($pValuePHPExcel_Cell_DataType::getErrorCodes())) {
  89.             return PHPExcel_Cell_DataType::TYPE_ERROR;
  90.  
  91.         else {
  92.             return PHPExcel_Cell_DataType::TYPE_STRING;
  93.  
  94.         }
  95.     }
  96. }

Documentation generated on Tue, 01 Jun 2010 17:02:44 +0200 by phpDocumentor 1.4.3