File Source for DataType.php

PHPExcel_Cell

# Source for file DataType.php

Documentation is available at DataType.php

1. <?php
2. /**
3. * PHPExcel
4. *
5. * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25. * @version 1.7.6, 2011-02-27
26. */
29. /**
30. * PHPExcel_Cell_DataType
31. *
32. * @category PHPExcel
33. * @package PHPExcel_Cell
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class 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 = 's';
45. const TYPE_INLINE = 'inlineStr';
46. const TYPE_ERROR = 'e';
48. /**
49. * List of error codes
50. *
51. * @var array
52. */
53. private static $_errorCodes = array('#NULL!' => 0, '#DIV/0!' => 1, '#VALUE!' => 2, '#REF!' => 3, '#NAME?' => 4, '#NUM!' => 5, '#N/A' => 6);
55. /**
56. * Get list of error codes
57. *
58. * @return array
59. */
60. public static function getErrorCodes() {
61. return self::$_errorCodes;
62. }
64. /**
65. * DataType for value
66. *
67. * @deprecated Replaced by PHPExcel_Cell_IValueBinder infrastructure
68. * @param mixed $pValue
69. * @return int
70. */
71. public static function dataTypeForValue($pValue = null) {
72. return PHPExcel_Cell_DefaultValueBinder:: dataTypeForValue($pValue);
73. }
75. /**
76. * Check a string that it satisfies Excel requirements
77. *
78. * @param mixed Value to sanitize to an Excel string
79. * @return mixed Sanitized value
80. */
81. public static function checkString($pValue = null)
82. {
83. if ($pValue instanceof PHPExcel_RichText) {
84. // TODO: Sanitize Rich-Text string (max. character count is 32,767)
85. return $pValue;
86. }
88. // string must never be longer than 32,767 characters, truncate if necessary
89. $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);
94. return $pValue;
95. }
97. /**
98. * Check a value that it is a valid error code
99. *
100. * @param mixed Value to sanitize to an Excel error code
101. * @return string Sanitized value
102. */
103. public static function checkErrorCode($pValue = null)
104. {
105. $pValue = (string)$pValue;
107. if ( ! array_key_exists($pValue, self::$_errorCodes) ) {
108. $pValue = '#NULL!';
109. }
111. return $pValue;
112. }
114. }

Documentation generated on Sun, 27 Feb 2011 16:29:19 -0800 by phpDocumentor 1.4.3