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

Documentation generated on Mon, 10 Aug 2009 08:03:08 +0200 by phpDocumentor 1.4.1