Source for file TextData.php
Documentation is available at TextData.php
* Copyright (c) 2006 - 2011 PHPExcel
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.6, 2011-02-27
/** PHPExcel root directory */
define('PHPEXCEL_ROOT', dirname(__FILE__ ) . '/../../');
require (PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
* PHPExcel_Calculation_TextData
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
private static $_invalidChars = Null;
private static function _uniord($c) {
if (ord($c{0}) >= 0 && ord($c{0}) <= 127)
if (ord($c{0}) >= 192 && ord($c{0}) <= 223)
return (ord($c{0})- 192)* 64 + (ord($c{1})- 128);
if (ord($c{0}) >= 224 && ord($c{0}) <= 239)
return (ord($c{0})- 224)* 4096 + (ord($c{1})- 128)* 64 + (ord($c{2})- 128);
if (ord($c{0}) >= 240 && ord($c{0}) <= 247)
return (ord($c{0})- 240)* 262144 + (ord($c{1})- 128)* 4096 + (ord($c{2})- 128)* 64 + (ord($c{3})- 128);
if (ord($c{0}) >= 248 && ord($c{0}) <= 251)
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);
if (ord($c{0}) >= 252 && ord($c{0}) <= 253)
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);
if (ord($c{0}) >= 254 && ord($c{0}) <= 255) //error
* @param string $character Value
public static function CHARACTER($character) {
if ((!is_numeric($character)) || ($character < 0)) {
* @param mixed $value Value to check
$stringValue = ($stringValue) ? 'TRUE' : 'FALSE';
if (self::$_invalidChars == Null) {
self::$_invalidChars = range(chr(0),chr(31));
return str_replace(self::$_invalidChars,'',trim($stringValue,"\x00..\x1F"));
} // function TRIMNONPRINTABLE()
* @param mixed $value Value to check
public static function TRIMSPACES($stringValue = '') {
} // function TRIMSPACES()
* @param string $character Value
public static function ASCIICODE($characters) {
$characters = (int) $characters;
$character = $characters;
if (mb_strlen($characters, 'UTF-8') > 1) { $character = mb_substr($characters, 0, 1, 'UTF-8'); }
return self::_uniord($character);
if (strlen($characters) > 0) { $character = substr($characters, 0, 1); }
} // function ASCIICODE()
// Loop through arguments
foreach ($aArgs as $arg) {
} // function CONCATENATE()
* This function converts a number to text using currency format, with the decimals rounded to the specified place.
* The format used is $#,##0.00_);($#,##0.00)..
* @param float $value The value to format
* @param int $decimals The number of digits to display to the right of the decimal point.
* If decimals is negative, number is rounded to the left of the decimal point.
* If you omit decimals, it is assumed to be 2
public static function DOLLAR($value = 0, $decimals = 2) {
$decimals = floor($decimals);
$round = pow(10,abs($decimals));
if ($value < 0) { $round = 0- $round; }
// The implementation of money_format used if the standard PHP function is not available can't handle decimal places of 0,
// so we display to 1 dp and chop off that character and the decimal separator using substr
* @param string $needle The string to look for
* @param string $haystack The string in which to look
* @param int $offset Offset within $haystack
$haystack = ($haystack) ? 'TRUE' : 'FALSE';
if (($offset > 0) && (strlen($haystack) > $offset)) {
$pos = mb_strpos($haystack, $needle, -- $offset,'UTF-8');
$pos = strpos($haystack, $needle, -- $offset);
} // function SEARCHSENSITIVE()
* @param string $needle The string to look for
* @param string $haystack The string in which to look
* @param int $offset Offset within $haystack
$haystack = ($haystack) ? 'TRUE' : 'FALSE';
if (($offset > 0) && (strlen($haystack) > $offset)) {
$pos = mb_stripos($haystack, $needle, -- $offset,'UTF-8');
$pos = stripos($haystack, $needle, -- $offset);
} // function SEARCHINSENSITIVE()
* @param mixed $value Value to check
public static function FIXEDFORMAT($value,$decimals= 2,$no_commas= false) {
$valueResult = round($value,$decimals);
if ($decimals < 0) { $decimals = 0; }
return (string) $valueResult;
} // function FIXEDFORMAT()
* @param string $value Value
* @param int $chars Number of characters
public static function LEFT($value = '', $chars = 1) {
$value = ($value) ? 'TRUE' : 'FALSE';
return mb_substr($value, 0, $chars, 'UTF-8');
return substr($value, 0, $chars);
* @param string $value Value
* @param int $start Start character
* @param int $chars Number of characters
public static function MID($value = '', $start = 1, $chars = null) {
if (($start < 1) || ($chars < 0)) {
$value = ($value) ? 'TRUE' : 'FALSE';
return mb_substr($value, -- $start, $chars, 'UTF-8');
return substr($value, -- $start, $chars);
* @param string $value Value
* @param int $chars Number of characters
public static function RIGHT($value = '', $chars = 1) {
$value = ($value) ? 'TRUE' : 'FALSE';
* @param string $value Value
* @param int $chars Number of characters
$value = ($value) ? 'TRUE' : 'FALSE';
} // function STRINGLENGTH()
* Converts a string value to upper case.
* @param string $mixedCaseString
public static function LOWERCASE($mixedCaseString) {
$mixedCaseString = ($mixedCaseString) ? 'TRUE' : 'FALSE';
} // function LOWERCASE()
* Converts a string value to upper case.
* @param string $mixedCaseString
public static function UPPERCASE($mixedCaseString) {
$mixedCaseString = ($mixedCaseString) ? 'TRUE' : 'FALSE';
} // function UPPERCASE()
* Converts a string value to upper case.
* @param string $mixedCaseString
public static function PROPERCASE($mixedCaseString) {
$mixedCaseString = ($mixedCaseString) ? 'TRUE' : 'FALSE';
} // function PROPERCASE()
* @param string $value Value
* @param int $start Start character
* @param int $chars Number of characters
public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText) {
$left = self::LEFT($oldText,$start- 1);
$right = self::RIGHT($oldText,self::STRINGLENGTH($oldText)- ($start+ $chars)+ 1);
return $left. $newText. $right;
* @param string $text Value
* @param string $fromText From Value
* @param string $toText To Value
* @param integer $instance Instance Number
public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) {
$pos = mb_strpos($text, $fromText, $pos+ 1, 'UTF-8');
$pos = strpos($text, $fromText, $pos+ 1);
return self::REPLACE($text,++ $pos,mb_strlen($fromText, 'UTF-8'),$toText);
return self::REPLACE($text,++ $pos,strlen($fromText),$toText);
return $left. $newText. $right;
} // function SUBSTITUTE()
* @param mixed $value Value to check
} // function RETURNSTRING()
* @param mixed $value Value to check
public static function TEXTFORMAT($value,$format) {
} // function TEXTFORMAT()
} // class PHPExcel_Calculation_TextData
|