← All changes
|
vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/TextData.php
+501
-522
3.1.1
→
3.0.10
View file →
| @@ -1,19 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -/** PHPExcel root directory */ | |
| 4 | -if (!defined('PHPEXCEL_ROOT')) { | |
| 5 | - /** | |
| 6 | - * @ignore | |
| 7 | - */ | |
| 8 | - define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); | |
| 9 | - require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | |
| 10 | -} | |
| 11 | - | |
| 12 | 2 | /** |
| 13 | - * PHPExcel_Calculation_TextData | |
| 3 | + * PHPExcel | |
| 14 | 4 | * |
| 15 | - * Copyright (c) 2006 - 2015 PHPExcel | |
| 5 | + * Copyright (c) 2006 - 2014 PHPExcel | |
| 16 | 6 | * |
| 17 | 7 | * This library is free software; you can redistribute it and/or |
| 18 | 8 | * modify it under the terms of the GNU Lesser General Public |
| 19 | 9 | * License as published by the Free Software Foundation; either |
| @@ -27,601 +17,589 @@ | ||
| 27 | 17 | * You should have received a copy of the GNU Lesser General Public |
| 28 | 18 | * License along with this library; if not, write to the Free Software |
| 29 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 30 | 20 | * |
| 31 | - * @category PHPExcel | |
| 32 | - * @package PHPExcel_Calculation | |
| 33 | - * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 34 | - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 35 | - * @version ##VERSION##, ##DATE## | |
| 21 | + * @category PHPExcel | |
| 22 | + * @package PHPExcel_Calculation | |
| 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## | |
| 36 | 26 | */ |
| 37 | -class PHPExcel_Calculation_TextData | |
| 38 | -{ | |
| 39 | - private static $invalidChars; | |
| 40 | 27 | |
| 41 | - private static function unicodeToOrd($c) | |
| 42 | - { | |
| 43 | - if (ord($c{0}) >=0 && ord($c{0}) <= 127) { | |
| 44 | - return ord($c{0}); | |
| 45 | - } elseif (ord($c{0}) >= 192 && ord($c{0}) <= 223) { | |
| 46 | - return (ord($c{0})-192)*64 + (ord($c{1})-128); | |
| 47 | - } elseif (ord($c{0}) >= 224 && ord($c{0}) <= 239) { | |
| 48 | - return (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128); | |
| 49 | - } elseif (ord($c{0}) >= 240 && ord($c{0}) <= 247) { | |
| 50 | - return (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128); | |
| 51 | - } elseif (ord($c{0}) >= 248 && ord($c{0}) <= 251) { | |
| 52 | - return (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128); | |
| 53 | - } elseif (ord($c{0}) >= 252 && ord($c{0}) <= 253) { | |
| 54 | - return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128); | |
| 55 | - } elseif (ord($c{0}) >= 254 && ord($c{0}) <= 255) { | |
| 56 | - // error | |
| 57 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 58 | - } | |
| 59 | - return 0; | |
| 60 | - } | |
| 61 | 28 | |
| 62 | - /** | |
| 63 | - * CHARACTER | |
| 64 | - * | |
| 65 | - * @param string $character Value | |
| 66 | - * @return int | |
| 67 | - */ | |
| 68 | - public static function CHARACTER($character) | |
| 69 | - { | |
| 70 | - $character = PHPExcel_Calculation_Functions::flattenSingleValue($character); | |
| 29 | +/** PHPExcel root directory */ | |
| 30 | +if (!defined('PHPEXCEL_ROOT')) { | |
| 31 | + /** | |
| 32 | + * @ignore | |
| 33 | + */ | |
| 34 | + define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); | |
| 35 | + require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | |
| 36 | +} | |
| 71 | 37 | |
| 72 | - if ((!is_numeric($character)) || ($character < 0)) { | |
| 73 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 74 | - } | |
| 75 | 38 | |
| 76 | - if (function_exists('mb_convert_encoding')) { | |
| 77 | - return mb_convert_encoding('&#'.intval($character).';', 'UTF-8', 'HTML-ENTITIES'); | |
| 78 | - } else { | |
| 79 | - return chr(intval($character)); | |
| 80 | - } | |
| 81 | - } | |
| 39 | +/** | |
| 40 | + * PHPExcel_Calculation_TextData | |
| 41 | + * | |
| 42 | + * @category PHPExcel | |
| 43 | + * @package PHPExcel_Calculation | |
| 44 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 45 | + */ | |
| 46 | +class PHPExcel_Calculation_TextData { | |
| 82 | 47 | |
| 48 | + private static $_invalidChars = Null; | |
| 83 | 49 | |
| 84 | - /** | |
| 85 | - * TRIMNONPRINTABLE | |
| 86 | - * | |
| 87 | - * @param mixed $stringValue Value to check | |
| 88 | - * @return string | |
| 89 | - */ | |
| 90 | - public static function TRIMNONPRINTABLE($stringValue = '') | |
| 91 | - { | |
| 92 | - $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); | |
| 50 | + private static function _uniord($c) { | |
| 51 | + if (ord($c{0}) >=0 && ord($c{0}) <= 127) | |
| 52 | + return ord($c{0}); | |
| 53 | + if (ord($c{0}) >= 192 && ord($c{0}) <= 223) | |
| 54 | + return (ord($c{0})-192)*64 + (ord($c{1})-128); | |
| 55 | + if (ord($c{0}) >= 224 && ord($c{0}) <= 239) | |
| 56 | + return (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128); | |
| 57 | + if (ord($c{0}) >= 240 && ord($c{0}) <= 247) | |
| 58 | + return (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128); | |
| 59 | + if (ord($c{0}) >= 248 && ord($c{0}) <= 251) | |
| 60 | + return (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128); | |
| 61 | + if (ord($c{0}) >= 252 && ord($c{0}) <= 253) | |
| 62 | + return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128); | |
| 63 | + if (ord($c{0}) >= 254 && ord($c{0}) <= 255) //error | |
| 64 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 65 | + return 0; | |
| 66 | + } // function _uniord() | |
| 93 | 67 | |
| 94 | - if (is_bool($stringValue)) { | |
| 95 | - return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 96 | - } | |
| 68 | + /** | |
| 69 | + * CHARACTER | |
| 70 | + * | |
| 71 | + * @param string $character Value | |
| 72 | + * @return int | |
| 73 | + */ | |
| 74 | + public static function CHARACTER($character) { | |
| 75 | + $character = PHPExcel_Calculation_Functions::flattenSingleValue($character); | |
| 97 | 76 | |
| 98 | - if (self::$invalidChars == null) { | |
| 99 | - self::$invalidChars = range(chr(0), chr(31)); | |
| 100 | - } | |
| 77 | + if ((!is_numeric($character)) || ($character < 0)) { | |
| 78 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 79 | + } | |
| 101 | 80 | |
| 102 | - if (is_string($stringValue) || is_numeric($stringValue)) { | |
| 103 | - return str_replace(self::$invalidChars, '', trim($stringValue, "\x00..\x1F")); | |
| 104 | - } | |
| 105 | - return null; | |
| 106 | - } | |
| 81 | + if (function_exists('mb_convert_encoding')) { | |
| 82 | + return mb_convert_encoding('&#'.intval($character).';', 'UTF-8', 'HTML-ENTITIES'); | |
| 83 | + } else { | |
| 84 | + return chr(intval($character)); | |
| 85 | + } | |
| 86 | + } | |
| 107 | 87 | |
| 108 | 88 | |
| 109 | - /** | |
| 110 | - * TRIMSPACES | |
| 111 | - * | |
| 112 | - * @param mixed $stringValue Value to check | |
| 113 | - * @return string | |
| 114 | - */ | |
| 115 | - public static function TRIMSPACES($stringValue = '') | |
| 116 | - { | |
| 117 | - $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); | |
| 118 | - if (is_bool($stringValue)) { | |
| 119 | - return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 120 | - } | |
| 89 | + /** | |
| 90 | + * TRIMNONPRINTABLE | |
| 91 | + * | |
| 92 | + * @param mixed $stringValue Value to check | |
| 93 | + * @return string | |
| 94 | + */ | |
| 95 | + public static function TRIMNONPRINTABLE($stringValue = '') { | |
| 96 | + $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); | |
| 121 | 97 | |
| 122 | - if (is_string($stringValue) || is_numeric($stringValue)) { | |
| 123 | - return trim(preg_replace('/ +/', ' ', trim($stringValue, ' ')), ' '); | |
| 124 | - } | |
| 125 | - return null; | |
| 126 | - } | |
| 98 | + if (is_bool($stringValue)) { | |
| 99 | + return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 100 | + } | |
| 127 | 101 | |
| 102 | + if (self::$_invalidChars == Null) { | |
| 103 | + self::$_invalidChars = range(chr(0),chr(31)); | |
| 104 | + } | |
| 128 | 105 | |
| 129 | - /** | |
| 130 | - * ASCIICODE | |
| 131 | - * | |
| 132 | - * @param string $characters Value | |
| 133 | - * @return int | |
| 134 | - */ | |
| 135 | - public static function ASCIICODE($characters) | |
| 136 | - { | |
| 137 | - if (($characters === null) || ($characters === '')) { | |
| 138 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 139 | - } | |
| 140 | - $characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters); | |
| 141 | - if (is_bool($characters)) { | |
| 142 | - if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { | |
| 143 | - $characters = (int) $characters; | |
| 144 | - } else { | |
| 145 | - $characters = ($characters) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 146 | - } | |
| 147 | - } | |
| 106 | + if (is_string($stringValue) || is_numeric($stringValue)) { | |
| 107 | + return str_replace(self::$_invalidChars, '', trim($stringValue, "\x00..\x1F")); | |
| 108 | + } | |
| 109 | + return NULL; | |
| 110 | + } // function TRIMNONPRINTABLE() | |
| 148 | 111 | |
| 149 | - $character = $characters; | |
| 150 | - if ((function_exists('mb_strlen')) && (function_exists('mb_substr'))) { | |
| 151 | - if (mb_strlen($characters, 'UTF-8') > 1) { | |
| 152 | - $character = mb_substr($characters, 0, 1, 'UTF-8'); | |
| 153 | - } | |
| 154 | - return self::unicodeToOrd($character); | |
| 155 | - } else { | |
| 156 | - if (strlen($characters) > 0) { | |
| 157 | - $character = substr($characters, 0, 1); | |
| 158 | - } | |
| 159 | - return ord($character); | |
| 160 | - } | |
| 161 | - } | |
| 162 | 112 | |
| 113 | + /** | |
| 114 | + * TRIMSPACES | |
| 115 | + * | |
| 116 | + * @param mixed $stringValue Value to check | |
| 117 | + * @return string | |
| 118 | + */ | |
| 119 | + public static function TRIMSPACES($stringValue = '') { | |
| 120 | + $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); | |
| 121 | + if (is_bool($stringValue)) { | |
| 122 | + return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 123 | + } | |
| 163 | 124 | |
| 164 | - /** | |
| 165 | - * CONCATENATE | |
| 166 | - * | |
| 167 | - * @return string | |
| 168 | - */ | |
| 169 | - public static function CONCATENATE() | |
| 170 | - { | |
| 171 | - $returnValue = ''; | |
| 125 | + if (is_string($stringValue) || is_numeric($stringValue)) { | |
| 126 | + return trim(preg_replace('/ +/',' ',trim($stringValue, ' ')), ' '); | |
| 127 | + } | |
| 128 | + return NULL; | |
| 129 | + } // function TRIMSPACES() | |
| 172 | 130 | |
| 173 | - // Loop through arguments | |
| 174 | - $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); | |
| 175 | - foreach ($aArgs as $arg) { | |
| 176 | - if (is_bool($arg)) { | |
| 177 | - if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { | |
| 178 | - $arg = (int) $arg; | |
| 179 | - } else { | |
| 180 | - $arg = ($arg) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 181 | - } | |
| 182 | - } | |
| 183 | - $returnValue .= $arg; | |
| 184 | - } | |
| 185 | 131 | |
| 186 | - return $returnValue; | |
| 187 | - } | |
| 132 | + /** | |
| 133 | + * ASCIICODE | |
| 134 | + * | |
| 135 | + * @param string $characters Value | |
| 136 | + * @return int | |
| 137 | + */ | |
| 138 | + public static function ASCIICODE($characters) { | |
| 139 | + if (($characters === NULL) || ($characters === '')) | |
| 140 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 141 | + $characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters); | |
| 142 | + if (is_bool($characters)) { | |
| 143 | + if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { | |
| 144 | + $characters = (int) $characters; | |
| 145 | + } else { | |
| 146 | + $characters = ($characters) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 147 | + } | |
| 148 | + } | |
| 188 | 149 | |
| 150 | + $character = $characters; | |
| 151 | + if ((function_exists('mb_strlen')) && (function_exists('mb_substr'))) { | |
| 152 | + if (mb_strlen($characters, 'UTF-8') > 1) { $character = mb_substr($characters, 0, 1, 'UTF-8'); } | |
| 153 | + return self::_uniord($character); | |
| 154 | + } else { | |
| 155 | + if (strlen($characters) > 0) { $character = substr($characters, 0, 1); } | |
| 156 | + return ord($character); | |
| 157 | + } | |
| 158 | + } // function ASCIICODE() | |
| 189 | 159 | |
| 190 | - /** | |
| 191 | - * DOLLAR | |
| 192 | - * | |
| 193 | - * This function converts a number to text using currency format, with the decimals rounded to the specified place. | |
| 194 | - * The format used is $#,##0.00_);($#,##0.00).. | |
| 195 | - * | |
| 196 | - * @param float $value The value to format | |
| 197 | - * @param int $decimals The number of digits to display to the right of the decimal point. | |
| 198 | - * If decimals is negative, number is rounded to the left of the decimal point. | |
| 199 | - * If you omit decimals, it is assumed to be 2 | |
| 200 | - * @return string | |
| 201 | - */ | |
| 202 | - public static function DOLLAR($value = 0, $decimals = 2) | |
| 203 | - { | |
| 204 | - $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 205 | - $decimals = is_null($decimals) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($decimals); | |
| 206 | 160 | |
| 207 | - // Validate parameters | |
| 208 | - if (!is_numeric($value) || !is_numeric($decimals)) { | |
| 209 | - return PHPExcel_Calculation_Functions::NaN(); | |
| 210 | - } | |
| 211 | - $decimals = floor($decimals); | |
| 161 | + /** | |
| 162 | + * CONCATENATE | |
| 163 | + * | |
| 164 | + * @return string | |
| 165 | + */ | |
| 166 | + public static function CONCATENATE() { | |
| 167 | + // Return value | |
| 168 | + $returnValue = ''; | |
| 212 | 169 | |
| 213 | - $mask = '$#,##0'; | |
| 214 | - if ($decimals > 0) { | |
| 215 | - $mask .= '.' . str_repeat('0', $decimals); | |
| 216 | - } else { | |
| 217 | - $round = pow(10, abs($decimals)); | |
| 218 | - if ($value < 0) { | |
| 219 | - $round = 0-$round; | |
| 220 | - } | |
| 221 | - $value = PHPExcel_Calculation_MathTrig::MROUND($value, $round); | |
| 222 | - } | |
| 170 | + // Loop through arguments | |
| 171 | + $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); | |
| 172 | + foreach ($aArgs as $arg) { | |
| 173 | + if (is_bool($arg)) { | |
| 174 | + if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { | |
| 175 | + $arg = (int) $arg; | |
| 176 | + } else { | |
| 177 | + $arg = ($arg) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 178 | + } | |
| 179 | + } | |
| 180 | + $returnValue .= $arg; | |
| 181 | + } | |
| 223 | 182 | |
| 224 | - return PHPExcel_Style_NumberFormat::toFormattedString($value, $mask); | |
| 183 | + // Return | |
| 184 | + return $returnValue; | |
| 185 | + } // function CONCATENATE() | |
| 225 | 186 | |
| 226 | - } | |
| 227 | 187 | |
| 188 | + /** | |
| 189 | + * DOLLAR | |
| 190 | + * | |
| 191 | + * This function converts a number to text using currency format, with the decimals rounded to the specified place. | |
| 192 | + * The format used is $#,##0.00_);($#,##0.00).. | |
| 193 | + * | |
| 194 | + * @param float $value The value to format | |
| 195 | + * @param int $decimals The number of digits to display to the right of the decimal point. | |
| 196 | + * If decimals is negative, number is rounded to the left of the decimal point. | |
| 197 | + * If you omit decimals, it is assumed to be 2 | |
| 198 | + * @return string | |
| 199 | + */ | |
| 200 | + public static function DOLLAR($value = 0, $decimals = 2) { | |
| 201 | + $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 202 | + $decimals = is_null($decimals) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($decimals); | |
| 228 | 203 | |
| 229 | - /** | |
| 230 | - * SEARCHSENSITIVE | |
| 231 | - * | |
| 232 | - * @param string $needle The string to look for | |
| 233 | - * @param string $haystack The string in which to look | |
| 234 | - * @param int $offset Offset within $haystack | |
| 235 | - * @return string | |
| 236 | - */ | |
| 237 | - public static function SEARCHSENSITIVE($needle, $haystack, $offset = 1) | |
| 238 | - { | |
| 239 | - $needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); | |
| 240 | - $haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); | |
| 241 | - $offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); | |
| 204 | + // Validate parameters | |
| 205 | + if (!is_numeric($value) || !is_numeric($decimals)) { | |
| 206 | + return PHPExcel_Calculation_Functions::NaN(); | |
| 207 | + } | |
| 208 | + $decimals = floor($decimals); | |
| 242 | 209 | |
| 243 | - if (!is_bool($needle)) { | |
| 244 | - if (is_bool($haystack)) { | |
| 245 | - $haystack = ($haystack) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 246 | - } | |
| 210 | + $mask = '$#,##0'; | |
| 211 | + if ($decimals > 0) { | |
| 212 | + $mask .= '.' . str_repeat('0',$decimals); | |
| 213 | + } else { | |
| 214 | + $round = pow(10,abs($decimals)); | |
| 215 | + if ($value < 0) { $round = 0-$round; } | |
| 216 | + $value = PHPExcel_Calculation_MathTrig::MROUND($value, $round); | |
| 217 | + } | |
| 247 | 218 | |
| 248 | - if (($offset > 0) && (PHPExcel_Shared_String::CountCharacters($haystack) > $offset)) { | |
| 249 | - if (PHPExcel_Shared_String::CountCharacters($needle) == 0) { | |
| 250 | - return $offset; | |
| 251 | - } | |
| 252 | - if (function_exists('mb_strpos')) { | |
| 253 | - $pos = mb_strpos($haystack, $needle, --$offset, 'UTF-8'); | |
| 254 | - } else { | |
| 255 | - $pos = strpos($haystack, $needle, --$offset); | |
| 256 | - } | |
| 257 | - if ($pos !== false) { | |
| 258 | - return ++$pos; | |
| 259 | - } | |
| 260 | - } | |
| 261 | - } | |
| 262 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 263 | - } | |
| 219 | + return PHPExcel_Style_NumberFormat::toFormattedString($value, $mask); | |
| 264 | 220 | |
| 221 | + } // function DOLLAR() | |
| 265 | 222 | |
| 266 | - /** | |
| 267 | - * SEARCHINSENSITIVE | |
| 268 | - * | |
| 269 | - * @param string $needle The string to look for | |
| 270 | - * @param string $haystack The string in which to look | |
| 271 | - * @param int $offset Offset within $haystack | |
| 272 | - * @return string | |
| 273 | - */ | |
| 274 | - public static function SEARCHINSENSITIVE($needle, $haystack, $offset = 1) | |
| 275 | - { | |
| 276 | - $needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); | |
| 277 | - $haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); | |
| 278 | - $offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); | |
| 279 | 223 | |
| 280 | - if (!is_bool($needle)) { | |
| 281 | - if (is_bool($haystack)) { | |
| 282 | - $haystack = ($haystack) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 283 | - } | |
| 224 | + /** | |
| 225 | + * SEARCHSENSITIVE | |
| 226 | + * | |
| 227 | + * @param string $needle The string to look for | |
| 228 | + * @param string $haystack The string in which to look | |
| 229 | + * @param int $offset Offset within $haystack | |
| 230 | + * @return string | |
| 231 | + */ | |
| 232 | + public static function SEARCHSENSITIVE($needle,$haystack,$offset=1) { | |
| 233 | + $needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); | |
| 234 | + $haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); | |
| 235 | + $offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); | |
| 284 | 236 | |
| 285 | - if (($offset > 0) && (PHPExcel_Shared_String::CountCharacters($haystack) > $offset)) { | |
| 286 | - if (PHPExcel_Shared_String::CountCharacters($needle) == 0) { | |
| 287 | - return $offset; | |
| 288 | - } | |
| 289 | - if (function_exists('mb_stripos')) { | |
| 290 | - $pos = mb_stripos($haystack, $needle, --$offset, 'UTF-8'); | |
| 291 | - } else { | |
| 292 | - $pos = stripos($haystack, $needle, --$offset); | |
| 293 | - } | |
| 294 | - if ($pos !== false) { | |
| 295 | - return ++$pos; | |
| 296 | - } | |
| 297 | - } | |
| 298 | - } | |
| 299 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 300 | - } | |
| 237 | + if (!is_bool($needle)) { | |
| 238 | + if (is_bool($haystack)) { | |
| 239 | + $haystack = ($haystack) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 240 | + } | |
| 301 | 241 | |
| 242 | + if (($offset > 0) && (PHPExcel_Shared_String::CountCharacters($haystack) > $offset)) { | |
| 243 | + if (PHPExcel_Shared_String::CountCharacters($needle) == 0) { | |
| 244 | + return $offset; | |
| 245 | + } | |
| 246 | + if (function_exists('mb_strpos')) { | |
| 247 | + $pos = mb_strpos($haystack, $needle, --$offset, 'UTF-8'); | |
| 248 | + } else { | |
| 249 | + $pos = strpos($haystack, $needle, --$offset); | |
| 250 | + } | |
| 251 | + if ($pos !== false) { | |
| 252 | + return ++$pos; | |
| 253 | + } | |
| 254 | + } | |
| 255 | + } | |
| 256 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 257 | + } // function SEARCHSENSITIVE() | |
| 302 | 258 | |
| 303 | - /** | |
| 304 | - * FIXEDFORMAT | |
| 305 | - * | |
| 306 | - * @param mixed $value Value to check | |
| 307 | - * @param integer $decimals | |
| 308 | - * @param boolean $no_commas | |
| 309 | - * @return boolean | |
| 310 | - */ | |
| 311 | - public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = false) | |
| 312 | - { | |
| 313 | - $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 314 | - $decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals); | |
| 315 | - $no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas); | |
| 316 | 259 | |
| 317 | - // Validate parameters | |
| 318 | - if (!is_numeric($value) || !is_numeric($decimals)) { | |
| 319 | - return PHPExcel_Calculation_Functions::NaN(); | |
| 320 | - } | |
| 321 | - $decimals = floor($decimals); | |
| 260 | + /** | |
| 261 | + * SEARCHINSENSITIVE | |
| 262 | + * | |
| 263 | + * @param string $needle The string to look for | |
| 264 | + * @param string $haystack The string in which to look | |
| 265 | + * @param int $offset Offset within $haystack | |
| 266 | + * @return string | |
| 267 | + */ | |
| 268 | + public static function SEARCHINSENSITIVE($needle,$haystack,$offset=1) { | |
| 269 | + $needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); | |
| 270 | + $haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); | |
| 271 | + $offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); | |
| 322 | 272 | |
| 323 | - $valueResult = round($value, $decimals); | |
| 324 | - if ($decimals < 0) { | |
| 325 | - $decimals = 0; | |
| 326 | - } | |
| 327 | - if (!$no_commas) { | |
| 328 | - $valueResult = number_format($valueResult, $decimals); | |
| 329 | - } | |
| 273 | + if (!is_bool($needle)) { | |
| 274 | + if (is_bool($haystack)) { | |
| 275 | + $haystack = ($haystack) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 276 | + } | |
| 330 | 277 | |
| 331 | - return (string) $valueResult; | |
| 332 | - } | |
| 278 | + if (($offset > 0) && (PHPExcel_Shared_String::CountCharacters($haystack) > $offset)) { | |
| 279 | + if (PHPExcel_Shared_String::CountCharacters($needle) == 0) { | |
| 280 | + return $offset; | |
| 281 | + } | |
| 282 | + if (function_exists('mb_stripos')) { | |
| 283 | + $pos = mb_stripos($haystack, $needle, --$offset,'UTF-8'); | |
| 284 | + } else { | |
| 285 | + $pos = stripos($haystack, $needle, --$offset); | |
| 286 | + } | |
| 287 | + if ($pos !== false) { | |
| 288 | + return ++$pos; | |
| 289 | + } | |
| 290 | + } | |
| 291 | + } | |
| 292 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 293 | + } // function SEARCHINSENSITIVE() | |
| 333 | 294 | |
| 334 | 295 | |
| 335 | - /** | |
| 336 | - * LEFT | |
| 337 | - * | |
| 338 | - * @param string $value Value | |
| 339 | - * @param int $chars Number of characters | |
| 340 | - * @return string | |
| 341 | - */ | |
| 342 | - public static function LEFT($value = '', $chars = 1) | |
| 343 | - { | |
| 344 | - $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 345 | - $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); | |
| 296 | + /** | |
| 297 | + * FIXEDFORMAT | |
| 298 | + * | |
| 299 | + * @param mixed $value Value to check | |
| 300 | + * @param integer $decimals | |
| 301 | + * @param boolean $no_commas | |
| 302 | + * @return boolean | |
| 303 | + */ | |
| 304 | + public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = FALSE) { | |
| 305 | + $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 306 | + $decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals); | |
| 307 | + $no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas); | |
| 346 | 308 | |
| 347 | - if ($chars < 0) { | |
| 348 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 349 | - } | |
| 309 | + // Validate parameters | |
| 310 | + if (!is_numeric($value) || !is_numeric($decimals)) { | |
| 311 | + return PHPExcel_Calculation_Functions::NaN(); | |
| 312 | + } | |
| 313 | + $decimals = floor($decimals); | |
| 350 | 314 | |
| 351 | - if (is_bool($value)) { | |
| 352 | - $value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 353 | - } | |
| 315 | + $valueResult = round($value,$decimals); | |
| 316 | + if ($decimals < 0) { $decimals = 0; } | |
| 317 | + if (!$no_commas) { | |
| 318 | + $valueResult = number_format($valueResult,$decimals); | |
| 319 | + } | |
| 354 | 320 | |
| 355 | - if (function_exists('mb_substr')) { | |
| 356 | - return mb_substr($value, 0, $chars, 'UTF-8'); | |
| 357 | - } else { | |
| 358 | - return substr($value, 0, $chars); | |
| 359 | - } | |
| 360 | - } | |
| 321 | + return (string) $valueResult; | |
| 322 | + } // function FIXEDFORMAT() | |
| 361 | 323 | |
| 362 | 324 | |
| 363 | - /** | |
| 364 | - * MID | |
| 365 | - * | |
| 366 | - * @param string $value Value | |
| 367 | - * @param int $start Start character | |
| 368 | - * @param int $chars Number of characters | |
| 369 | - * @return string | |
| 370 | - */ | |
| 371 | - public static function MID($value = '', $start = 1, $chars = null) | |
| 372 | - { | |
| 373 | - $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 374 | - $start = PHPExcel_Calculation_Functions::flattenSingleValue($start); | |
| 375 | - $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); | |
| 325 | + /** | |
| 326 | + * LEFT | |
| 327 | + * | |
| 328 | + * @param string $value Value | |
| 329 | + * @param int $chars Number of characters | |
| 330 | + * @return string | |
| 331 | + */ | |
| 332 | + public static function LEFT($value = '', $chars = 1) { | |
| 333 | + $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 334 | + $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); | |
| 376 | 335 | |
| 377 | - if (($start < 1) || ($chars < 0)) { | |
| 378 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 379 | - } | |
| 336 | + if ($chars < 0) { | |
| 337 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 338 | + } | |
| 380 | 339 | |
| 381 | - if (is_bool($value)) { | |
| 382 | - $value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 383 | - } | |
| 340 | + if (is_bool($value)) { | |
| 341 | + $value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 342 | + } | |
| 384 | 343 | |
| 385 | - if (function_exists('mb_substr')) { | |
| 386 | - return mb_substr($value, --$start, $chars, 'UTF-8'); | |
| 387 | - } else { | |
| 388 | - return substr($value, --$start, $chars); | |
| 389 | - } | |
| 390 | - } | |
| 344 | + if (function_exists('mb_substr')) { | |
| 345 | + return mb_substr($value, 0, $chars, 'UTF-8'); | |
| 346 | + } else { | |
| 347 | + return substr($value, 0, $chars); | |
| 348 | + } | |
| 349 | + } // function LEFT() | |
| 391 | 350 | |
| 392 | 351 | |
| 393 | - /** | |
| 394 | - * RIGHT | |
| 395 | - * | |
| 396 | - * @param string $value Value | |
| 397 | - * @param int $chars Number of characters | |
| 398 | - * @return string | |
| 399 | - */ | |
| 400 | - public static function RIGHT($value = '', $chars = 1) | |
| 401 | - { | |
| 402 | - $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 403 | - $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); | |
| 352 | + /** | |
| 353 | + * MID | |
| 354 | + * | |
| 355 | + * @param string $value Value | |
| 356 | + * @param int $start Start character | |
| 357 | + * @param int $chars Number of characters | |
| 358 | + * @return string | |
| 359 | + */ | |
| 360 | + public static function MID($value = '', $start = 1, $chars = null) { | |
| 361 | + $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 362 | + $start = PHPExcel_Calculation_Functions::flattenSingleValue($start); | |
| 363 | + $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); | |
| 404 | 364 | |
| 405 | - if ($chars < 0) { | |
| 406 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 407 | - } | |
| 365 | + if (($start < 1) || ($chars < 0)) { | |
| 366 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 367 | + } | |
| 408 | 368 | |
| 409 | - if (is_bool($value)) { | |
| 410 | - $value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 411 | - } | |
| 369 | + if (is_bool($value)) { | |
| 370 | + $value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 371 | + } | |
| 412 | 372 | |
| 413 | - if ((function_exists('mb_substr')) && (function_exists('mb_strlen'))) { | |
| 414 | - return mb_substr($value, mb_strlen($value, 'UTF-8') - $chars, $chars, 'UTF-8'); | |
| 415 | - } else { | |
| 416 | - return substr($value, strlen($value) - $chars); | |
| 417 | - } | |
| 418 | - } | |
| 373 | + if (function_exists('mb_substr')) { | |
| 374 | + return mb_substr($value, --$start, $chars, 'UTF-8'); | |
| 375 | + } else { | |
| 376 | + return substr($value, --$start, $chars); | |
| 377 | + } | |
| 378 | + } // function MID() | |
| 419 | 379 | |
| 420 | 380 | |
| 421 | - /** | |
| 422 | - * STRINGLENGTH | |
| 423 | - * | |
| 424 | - * @param string $value Value | |
| 425 | - * @return string | |
| 426 | - */ | |
| 427 | - public static function STRINGLENGTH($value = '') | |
| 428 | - { | |
| 429 | - $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 381 | + /** | |
| 382 | + * RIGHT | |
| 383 | + * | |
| 384 | + * @param string $value Value | |
| 385 | + * @param int $chars Number of characters | |
| 386 | + * @return string | |
| 387 | + */ | |
| 388 | + public static function RIGHT($value = '', $chars = 1) { | |
| 389 | + $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 390 | + $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); | |
| 430 | 391 | |
| 431 | - if (is_bool($value)) { | |
| 432 | - $value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 433 | - } | |
| 392 | + if ($chars < 0) { | |
| 393 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 394 | + } | |
| 434 | 395 | |
| 435 | - if (function_exists('mb_strlen')) { | |
| 436 | - return mb_strlen($value, 'UTF-8'); | |
| 437 | - } else { | |
| 438 | - return strlen($value); | |
| 439 | - } | |
| 440 | - } | |
| 396 | + if (is_bool($value)) { | |
| 397 | + $value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 398 | + } | |
| 441 | 399 | |
| 400 | + if ((function_exists('mb_substr')) && (function_exists('mb_strlen'))) { | |
| 401 | + return mb_substr($value, mb_strlen($value, 'UTF-8') - $chars, $chars, 'UTF-8'); | |
| 402 | + } else { | |
| 403 | + return substr($value, strlen($value) - $chars); | |
| 404 | + } | |
| 405 | + } // function RIGHT() | |
| 442 | 406 | |
| 443 | - /** | |
| 444 | - * LOWERCASE | |
| 445 | - * | |
| 446 | - * Converts a string value to upper case. | |
| 447 | - * | |
| 448 | - * @param string $mixedCaseString | |
| 449 | - * @return string | |
| 450 | - */ | |
| 451 | - public static function LOWERCASE($mixedCaseString) | |
| 452 | - { | |
| 453 | - $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); | |
| 454 | 407 | |
| 455 | - if (is_bool($mixedCaseString)) { | |
| 456 | - $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 457 | - } | |
| 408 | + /** | |
| 409 | + * STRINGLENGTH | |
| 410 | + * | |
| 411 | + * @param string $value Value | |
| 412 | + * @return string | |
| 413 | + */ | |
| 414 | + public static function STRINGLENGTH($value = '') { | |
| 415 | + $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 458 | 416 | |
| 459 | - return PHPExcel_Shared_String::StrToLower($mixedCaseString); | |
| 460 | - } | |
| 417 | + if (is_bool($value)) { | |
| 418 | + $value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 419 | + } | |
| 461 | 420 | |
| 421 | + if (function_exists('mb_strlen')) { | |
| 422 | + return mb_strlen($value, 'UTF-8'); | |
| 423 | + } else { | |
| 424 | + return strlen($value); | |
| 425 | + } | |
| 426 | + } // function STRINGLENGTH() | |
| 462 | 427 | |
| 463 | - /** | |
| 464 | - * UPPERCASE | |
| 465 | - * | |
| 466 | - * Converts a string value to upper case. | |
| 467 | - * | |
| 468 | - * @param string $mixedCaseString | |
| 469 | - * @return string | |
| 470 | - */ | |
| 471 | - public static function UPPERCASE($mixedCaseString) | |
| 472 | - { | |
| 473 | - $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); | |
| 474 | 428 | |
| 475 | - if (is_bool($mixedCaseString)) { | |
| 476 | - $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 477 | - } | |
| 429 | + /** | |
| 430 | + * LOWERCASE | |
| 431 | + * | |
| 432 | + * Converts a string value to upper case. | |
| 433 | + * | |
| 434 | + * @param string $mixedCaseString | |
| 435 | + * @return string | |
| 436 | + */ | |
| 437 | + public static function LOWERCASE($mixedCaseString) { | |
| 438 | + $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); | |
| 478 | 439 | |
| 479 | - return PHPExcel_Shared_String::StrToUpper($mixedCaseString); | |
| 480 | - } | |
| 440 | + if (is_bool($mixedCaseString)) { | |
| 441 | + $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 442 | + } | |
| 481 | 443 | |
| 444 | + return PHPExcel_Shared_String::StrToLower($mixedCaseString); | |
| 445 | + } // function LOWERCASE() | |
| 482 | 446 | |
| 483 | - /** | |
| 484 | - * PROPERCASE | |
| 485 | - * | |
| 486 | - * Converts a string value to upper case. | |
| 487 | - * | |
| 488 | - * @param string $mixedCaseString | |
| 489 | - * @return string | |
| 490 | - */ | |
| 491 | - public static function PROPERCASE($mixedCaseString) | |
| 492 | - { | |
| 493 | - $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); | |
| 494 | 447 | |
| 495 | - if (is_bool($mixedCaseString)) { | |
| 496 | - $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 497 | - } | |
| 448 | + /** | |
| 449 | + * UPPERCASE | |
| 450 | + * | |
| 451 | + * Converts a string value to upper case. | |
| 452 | + * | |
| 453 | + * @param string $mixedCaseString | |
| 454 | + * @return string | |
| 455 | + */ | |
| 456 | + public static function UPPERCASE($mixedCaseString) { | |
| 457 | + $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); | |
| 498 | 458 | |
| 499 | - return PHPExcel_Shared_String::StrToTitle($mixedCaseString); | |
| 500 | - } | |
| 459 | + if (is_bool($mixedCaseString)) { | |
| 460 | + $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 461 | + } | |
| 501 | 462 | |
| 463 | + return PHPExcel_Shared_String::StrToUpper($mixedCaseString); | |
| 464 | + } // function UPPERCASE() | |
| 502 | 465 | |
| 503 | - /** | |
| 504 | - * REPLACE | |
| 505 | - * | |
| 506 | - * @param string $oldText String to modify | |
| 507 | - * @param int $start Start character | |
| 508 | - * @param int $chars Number of characters | |
| 509 | - * @param string $newText String to replace in defined position | |
| 510 | - * @return string | |
| 511 | - */ | |
| 512 | - public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText) | |
| 513 | - { | |
| 514 | - $oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText); | |
| 515 | - $start = PHPExcel_Calculation_Functions::flattenSingleValue($start); | |
| 516 | - $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); | |
| 517 | - $newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText); | |
| 518 | 466 | |
| 519 | - $left = self::LEFT($oldText, $start-1); | |
| 520 | - $right = self::RIGHT($oldText, self::STRINGLENGTH($oldText)-($start+$chars)+1); | |
| 467 | + /** | |
| 468 | + * PROPERCASE | |
| 469 | + * | |
| 470 | + * Converts a string value to upper case. | |
| 471 | + * | |
| 472 | + * @param string $mixedCaseString | |
| 473 | + * @return string | |
| 474 | + */ | |
| 475 | + public static function PROPERCASE($mixedCaseString) { | |
| 476 | + $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); | |
| 521 | 477 | |
| 522 | - return $left.$newText.$right; | |
| 523 | - } | |
| 478 | + if (is_bool($mixedCaseString)) { | |
| 479 | + $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); | |
| 480 | + } | |
| 524 | 481 | |
| 482 | + return PHPExcel_Shared_String::StrToTitle($mixedCaseString); | |
| 483 | + } // function PROPERCASE() | |
| 525 | 484 | |
| 526 | - /** | |
| 527 | - * SUBSTITUTE | |
| 528 | - * | |
| 529 | - * @param string $text Value | |
| 530 | - * @param string $fromText From Value | |
| 531 | - * @param string $toText To Value | |
| 532 | - * @param integer $instance Instance Number | |
| 533 | - * @return string | |
| 534 | - */ | |
| 535 | - public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) | |
| 536 | - { | |
| 537 | - $text = PHPExcel_Calculation_Functions::flattenSingleValue($text); | |
| 538 | - $fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText); | |
| 539 | - $toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText); | |
| 540 | - $instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance)); | |
| 541 | 485 | |
| 542 | - if ($instance == 0) { | |
| 543 | - if (function_exists('mb_str_replace')) { | |
| 544 | - return mb_str_replace($fromText, $toText, $text); | |
| 545 | - } else { | |
| 546 | - return str_replace($fromText, $toText, $text); | |
| 547 | - } | |
| 548 | - } else { | |
| 549 | - $pos = -1; | |
| 550 | - while ($instance > 0) { | |
| 551 | - if (function_exists('mb_strpos')) { | |
| 552 | - $pos = mb_strpos($text, $fromText, $pos+1, 'UTF-8'); | |
| 553 | - } else { | |
| 554 | - $pos = strpos($text, $fromText, $pos+1); | |
| 555 | - } | |
| 556 | - if ($pos === false) { | |
| 557 | - break; | |
| 558 | - } | |
| 559 | - --$instance; | |
| 560 | - } | |
| 561 | - if ($pos !== false) { | |
| 562 | - if (function_exists('mb_strlen')) { | |
| 563 | - return self::REPLACE($text, ++$pos, mb_strlen($fromText, 'UTF-8'), $toText); | |
| 564 | - } else { | |
| 565 | - return self::REPLACE($text, ++$pos, strlen($fromText), $toText); | |
| 566 | - } | |
| 567 | - } | |
| 568 | - } | |
| 486 | + /** | |
| 487 | + * REPLACE | |
| 488 | + * | |
| 489 | + * @param string $oldText String to modify | |
| 490 | + * @param int $start Start character | |
| 491 | + * @param int $chars Number of characters | |
| 492 | + * @param string $newText String to replace in defined position | |
| 493 | + * @return string | |
| 494 | + */ | |
| 495 | + public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText) { | |
| 496 | + $oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText); | |
| 497 | + $start = PHPExcel_Calculation_Functions::flattenSingleValue($start); | |
| 498 | + $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); | |
| 499 | + $newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText); | |
| 569 | 500 | |
| 570 | - return $text; | |
| 571 | - } | |
| 501 | + $left = self::LEFT($oldText,$start-1); | |
| 502 | + $right = self::RIGHT($oldText,self::STRINGLENGTH($oldText)-($start+$chars)+1); | |
| 572 | 503 | |
| 504 | + return $left.$newText.$right; | |
| 505 | + } // function REPLACE() | |
| 573 | 506 | |
| 574 | - /** | |
| 575 | - * RETURNSTRING | |
| 576 | - * | |
| 577 | - * @param mixed $testValue Value to check | |
| 578 | - * @return boolean | |
| 579 | - */ | |
| 580 | - public static function RETURNSTRING($testValue = '') | |
| 581 | - { | |
| 582 | - $testValue = PHPExcel_Calculation_Functions::flattenSingleValue($testValue); | |
| 583 | 507 | |
| 584 | - if (is_string($testValue)) { | |
| 585 | - return $testValue; | |
| 586 | - } | |
| 587 | - return null; | |
| 588 | - } | |
| 508 | + /** | |
| 509 | + * SUBSTITUTE | |
| 510 | + * | |
| 511 | + * @param string $text Value | |
| 512 | + * @param string $fromText From Value | |
| 513 | + * @param string $toText To Value | |
| 514 | + * @param integer $instance Instance Number | |
| 515 | + * @return string | |
| 516 | + */ | |
| 517 | + public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) { | |
| 518 | + $text = PHPExcel_Calculation_Functions::flattenSingleValue($text); | |
| 519 | + $fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText); | |
| 520 | + $toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText); | |
| 521 | + $instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance)); | |
| 589 | 522 | |
| 523 | + if ($instance == 0) { | |
| 524 | + if(function_exists('mb_str_replace')) { | |
| 525 | + return mb_str_replace($fromText,$toText,$text); | |
| 526 | + } else { | |
| 527 | + return str_replace($fromText,$toText,$text); | |
| 528 | + } | |
| 529 | + } else { | |
| 530 | + $pos = -1; | |
| 531 | + while($instance > 0) { | |
| 532 | + if (function_exists('mb_strpos')) { | |
| 533 | + $pos = mb_strpos($text, $fromText, $pos+1, 'UTF-8'); | |
| 534 | + } else { | |
| 535 | + $pos = strpos($text, $fromText, $pos+1); | |
| 536 | + } | |
| 537 | + if ($pos === false) { | |
| 538 | + break; | |
| 539 | + } | |
| 540 | + --$instance; | |
| 541 | + } | |
| 542 | + if ($pos !== false) { | |
| 543 | + if (function_exists('mb_strlen')) { | |
| 544 | + return self::REPLACE($text,++$pos,mb_strlen($fromText, 'UTF-8'),$toText); | |
| 545 | + } else { | |
| 546 | + return self::REPLACE($text,++$pos,strlen($fromText),$toText); | |
| 547 | + } | |
| 548 | + } | |
| 549 | + } | |
| 590 | 550 | |
| 591 | - /** | |
| 592 | - * TEXTFORMAT | |
| 593 | - * | |
| 594 | - * @param mixed $value Value to check | |
| 595 | - * @param string $format Format mask to use | |
| 596 | - * @return boolean | |
| 597 | - */ | |
| 598 | - public static function TEXTFORMAT($value, $format) | |
| 599 | - { | |
| 600 | - $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 601 | - $format = PHPExcel_Calculation_Functions::flattenSingleValue($format); | |
| 551 | + return $text; | |
| 552 | + } // function SUBSTITUTE() | |
| 602 | 553 | |
| 603 | - if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) { | |
| 604 | - $value = PHPExcel_Calculation_DateTime::DATEVALUE($value); | |
| 605 | - } | |
| 606 | 554 | |
| 607 | - return (string) PHPExcel_Style_NumberFormat::toFormattedString($value, $format); | |
| 608 | - } | |
| 555 | + /** | |
| 556 | + * RETURNSTRING | |
| 557 | + * | |
| 558 | + * @param mixed $testValue Value to check | |
| 559 | + * @return boolean | |
| 560 | + */ | |
| 561 | + public static function RETURNSTRING($testValue = '') { | |
| 562 | + $testValue = PHPExcel_Calculation_Functions::flattenSingleValue($testValue); | |
| 609 | 563 | |
| 610 | - /** | |
| 611 | - * VALUE | |
| 612 | - * | |
| 613 | - * @param mixed $value Value to check | |
| 614 | - * @return boolean | |
| 615 | - */ | |
| 616 | - public static function VALUE($value = '') | |
| 617 | - { | |
| 618 | - $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 564 | + if (is_string($testValue)) { | |
| 565 | + return $testValue; | |
| 566 | + } | |
| 567 | + return Null; | |
| 568 | + } // function RETURNSTRING() | |
| 619 | 569 | |
| 620 | - if (!is_numeric($value)) { | |
| 570 | + | |
| 571 | + /** | |
| 572 | + * TEXTFORMAT | |
| 573 | + * | |
| 574 | + * @param mixed $value Value to check | |
| 575 | + * @param string $format Format mask to use | |
| 576 | + * @return boolean | |
| 577 | + */ | |
| 578 | + public static function TEXTFORMAT($value,$format) { | |
| 579 | + $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 580 | + $format = PHPExcel_Calculation_Functions::flattenSingleValue($format); | |
| 581 | + | |
| 582 | + if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) { | |
| 583 | + $value = PHPExcel_Calculation_DateTime::DATEVALUE($value); | |
| 584 | + } | |
| 585 | + | |
| 586 | + return (string) PHPExcel_Style_NumberFormat::toFormattedString($value,$format); | |
| 587 | + } // function TEXTFORMAT() | |
| 588 | + | |
| 589 | + /** | |
| 590 | + * VALUE | |
| 591 | + * | |
| 592 | + * @param mixed $value Value to check | |
| 593 | + * @return boolean | |
| 594 | + */ | |
| 595 | + public static function VALUE($value = '') { | |
| 596 | + $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); | |
| 597 | + | |
| 598 | + if (!is_numeric($value)) { | |
| 621 | 599 | $numberValue = str_replace( |
| 622 | - PHPExcel_Shared_String::getThousandsSeparator(), | |
| 623 | - '', | |
| 600 | + PHPExcel_Shared_String::getThousandsSeparator(), | |
| 601 | + '', | |
| 624 | 602 | trim($value, " \t\n\r\0\x0B" . PHPExcel_Shared_String::getCurrencyCode()) |
| 625 | 603 | ); |
| 626 | 604 | if (is_numeric($numberValue)) { |
| 627 | 605 | return (float) $numberValue; |
| @@ -636,9 +614,9 @@ | ||
| 636 | 614 | PHPExcel_Calculation_Functions::setReturnDateType($dateSetting); |
| 637 | 615 | return $timeValue; |
| 638 | 616 | } |
| 639 | 617 | } |
| 640 | - $dateValue = PHPExcel_Calculation_DateTime::DATEVALUE($value); | |
| 618 | + $dateValue = PHPExcel_Calculation_DateTime::DATEVALUE($value); | |
| 641 | 619 | if ($dateValue !== PHPExcel_Calculation_Functions::VALUE()) { |
| 642 | 620 | PHPExcel_Calculation_Functions::setReturnDateType($dateSetting); |
| 643 | 621 | return $dateValue; |
| 644 | 622 | } |
| @@ -643,9 +621,10 @@ | ||
| 643 | 621 | return $dateValue; |
| 644 | 622 | } |
| 645 | 623 | PHPExcel_Calculation_Functions::setReturnDateType($dateSetting); |
| 646 | 624 | |
| 647 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 648 | - } | |
| 649 | - return (float) $value; | |
| 650 | - } | |
| 625 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 626 | + } | |
| 627 | + return (float) $value; | |
| 628 | + } | |
| 629 | + | |
| 651 | 630 | } |