0973b6d822ddee9c8bd0964597e7d7da5c3d231c.svn-base 3.5 KB

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