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/** 30 * PHPExcel_Cell_DataType 31 * 32 * @category PHPExcel 33 * @package PHPExcel_Cell 34 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) 35 */ 36class PHPExcel_Cell_DataType 37{ 38 /* Data types */ 39 const TYPE_STRING2 = 'str'; 40 const TYPE_STRING = 's'; 41 const TYPE_FORMULA = 'f'; 42 const TYPE_NUMERIC = 'n'; 43 const TYPE_BOOL = 'b'; 44 const TYPE_NULL = 'null'; 45 const TYPE_INLINE = 'inlineStr'; 46 const TYPE_ERROR = 'e'; 47 48 /** 49 * List of error codes 50 * 51 * @var array 52 */ 53 private static $_errorCodes = array( 54 '#NULL!' => 0, 55 '#DIV/0!' => 1, 56 '#VALUE!' => 2, 57 '#REF!' => 3, 58 '#NAME?' => 4, 59 '#NUM!' => 5, 60 '#N/A' => 6 61 ); 62 63 /** 64 * Get list of error codes 65 * 66 * @return array 67 */ 68 public static function getErrorCodes() { 69 return self::$_errorCodes; 70 } 71 72 /** 73 * DataType for value 74 * 75 * @deprecated Replaced by PHPExcel_Cell_IValueBinder infrastructure, will be removed in version 1.8.0 76 * @param mixed $pValue 77 * @return string 78 */ 79 public static function dataTypeForValue($pValue = null) { 80 return PHPExcel_Cell_DefaultValueBinder::dataTypeForValue($pValue); 81 } 82 83 /** 84 * Check a string that it satisfies Excel requirements 85 * 86 * @param mixed Value to sanitize to an Excel string 87 * @return mixed Sanitized value 88 */ 89 public static function checkString($pValue = null) 90 { 91 if ($pValue instanceof PHPExcel_RichText) { 92 // TODO: Sanitize Rich-Text string (max. character count is 32,767) 93 return $pValue; 94 } 95 96 // string must never be longer than 32,767 characters, truncate if necessary 97 $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767); 98 99 // we require that newline is represented as "\n" in core, not as "\r\n" or "\r" 100 $pValue = str_replace(array("\r\n", "\r"), "\n", $pValue); 101 102 return $pValue; 103 } 104 105 /** 106 * Check a value that it is a valid error code 107 * 108 * @param mixed Value to sanitize to an Excel error code 109 * @return string Sanitized value 110 */ 111 public static function checkErrorCode($pValue = null) 112 { 113 $pValue = (string) $pValue; 114 115 if ( !array_key_exists($pValue, self::$_errorCodes) ) { 116 $pValue = '#NULL!'; 117 } 118 119 return $pValue; 120 } 121 122} 123