30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
35 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
40 define(
'MAX_VALUE', 1.2e308);
43 define(
'M_2DIVPI', 0.63661977236758134307553505349006);
46 define(
'MAX_ITERATIONS', 256);
49 define(
'PRECISION', 8.88E-016);
94 'divisionbyzero' =>
'#DIV/0!',
96 'reference' =>
'#REF!',
100 'gettingdata' =>
'#GETTING_DATA'
156 if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) ||
157 ($returnDateType == self::RETURNDATE_PHP_OBJECT) ||
158 ($returnDateType == self::RETURNDATE_EXCEL)) {
159 self::$ReturnDateType = $returnDateType;
190 return '#Not Yet Implemented';
201 public static function DIV0() {
202 return self::$_errorCodes[
'divisionbyzero'];
219 public static function NA() {
220 return self::$_errorCodes[
'na'];
233 public static function NaN() {
234 return self::$_errorCodes[
'num'];
247 public static function NAME() {
248 return self::$_errorCodes[
'name'];
261 public static function REF() {
262 return self::$_errorCodes[
'reference'];
275 public static function NULL() {
276 return self::$_errorCodes[
'null'];
290 return self::$_errorCodes[
'value'];
295 return ((substr_count($idx,
'.') <= 1) || (preg_match(
'/\.[A-Z]/',$idx) > 0));
300 return (substr_count($idx,
'.') == 0);
305 return (substr_count($idx,
'.') > 1);
311 if (!in_array($condition{0},array(
'>',
'<',
'='))) {
313 return '='.$condition;
315 preg_match(
'/([<>=]+)(.*)/',$condition,$matches);
316 list(,$operator,$operand) = $matches;
318 return $operator.$operand;
333 foreach(self::$_errorCodes as $errorCode) {
334 if ($value == $errorCode) {
339 return self::$_errorCodes[
'na'];
350 if (!is_null($value)) {
354 return is_null($value);
364 public static function IS_ERR($value =
'') {
380 return in_array($value, array_values(self::$_errorCodes));
390 public static function IS_NA($value =
'') {
393 return ($value === self::$_errorCodes[
'na']);
406 if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
407 return self::$_errorCodes[
'value'];
409 return ($value % 2 == 0);
419 public static function IS_ODD($value = null) {
422 if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
423 return self::$_errorCodes[
'value'];
425 return (abs($value) % 2 == 1);
438 if (is_string($value)) {
441 return is_numeric($value);
454 return is_bool($value);
467 return is_string($value);
488 return 'PHPExcel 1.7.6, 2011-02-27';
507 public static function N($value) {
508 while (is_array($value)) {
509 $value = array_shift($value);
512 switch (gettype($value)) {
519 return (integer) $value;
523 if ((strlen($value) > 0) && ($value{0} ==
'#')) {
546 public static function TYPE($value) {
548 if (is_array($value) && (count($value) > 1)) {
549 $a = array_keys($value);
552 if (self::isCellValue($a)) {
555 } elseif (self::isMatrixValue($a)) {
558 } elseif(count($value) == 0) {
564 if ((is_float($value)) || (is_int($value))) {
566 } elseif(is_bool($value)) {
568 } elseif(is_array($value)) {
571 } elseif(is_string($value)) {
573 if ((strlen($value) > 0) && ($value{0} ==
'#')) {
589 if (!is_array($array)) {
590 return (array) $array;
593 $arrayValues = array();
594 foreach ($array as $value) {
595 if (is_array($value)) {
596 foreach ($value as $val) {
597 if (is_array($val)) {
598 foreach ($val as $v) {
602 $arrayValues[] = $val;
606 $arrayValues[] = $value;
621 if (!is_array($array)) {
622 return (array) $array;
625 $arrayValues = array();
626 foreach ($array as $k1 => $value) {
627 if (is_array($value)) {
628 foreach ($value as $k2 => $val) {
629 if (is_array($val)) {
630 foreach ($val as $k3 => $v) {
631 $arrayValues[$k1.
'.'.$k2.
'.'.$k3] = $v;
634 $arrayValues[$k1.
'.'.$k2] = $val;
638 $arrayValues[$k1] = $value;
653 while (is_array($value)) {
654 $value = array_pop($value);
668 if (!function_exists(
'acosh')) {
670 return 2 * log(sqrt((
$x + 1) / 2) + sqrt((
$x - 1) / 2));
674 if (!function_exists(
'asinh')) {
676 return log(
$x + sqrt(1 +
$x *
$x));
680 if (!function_exists(
'atanh')) {
682 return (log(1 +
$x) - log(1 -
$x)) / 2;
686 if (!function_exists(
'money_format')) {
687 function money_format($format, $number) {
688 $regex = array(
'/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?(?:#([0-9]+))?',
689 '(?:\.([0-9]+))?([in%])/'
691 $regex = implode(
'', $regex);
692 if (setlocale(LC_MONETARY, null) ==
'') {
693 setlocale(LC_MONETARY,
'');
695 $locale = localeconv();
696 $number = floatval($number);
697 if (!preg_match($regex, $format, $fmatch)) {
698 trigger_error(
"No format specified or invalid format", E_USER_WARNING);
701 $flags = array(
'fillchar' => preg_match(
'/\=(.)/', $fmatch[1], $match) ? $match[1] :
' ',
702 'nogroup' => preg_match(
'/\^/', $fmatch[1]) > 0,
703 'usesignal' => preg_match(
'/\+|\(/', $fmatch[1], $match) ? $match[0] :
'+',
704 'nosimbol' => preg_match(
'/\!/', $fmatch[1]) > 0,
705 'isleft' => preg_match(
'/\-/', $fmatch[1]) > 0
707 $width = trim($fmatch[2]) ? (int)$fmatch[2] : 0;
708 $left = trim($fmatch[3]) ? (int)$fmatch[3] : 0;
709 $right = trim($fmatch[4]) ? (int)$fmatch[4] : $locale[
'int_frac_digits'];
710 $conversion = $fmatch[5];
716 $letter = $positive ?
'p' :
'n';
717 $prefix = $suffix = $cprefix = $csuffix = $signal =
'';
719 $signal = $locale[
'negative_sign'];
721 case $locale[
'n_sign_posn'] == 0 || $flags[
'usesignal'] ==
'(':
725 case $locale[
'n_sign_posn'] == 1:
728 case $locale[
'n_sign_posn'] == 2:
731 case $locale[
'n_sign_posn'] == 3:
734 case $locale[
'n_sign_posn'] == 4:
739 if (!$flags[
'nosimbol']) {
740 $currency = $cprefix;
741 $currency .= ($conversion ==
'i' ? $locale[
'int_curr_symbol'] : $locale[
'currency_symbol']);
742 $currency .= $csuffix;
743 $currency = iconv(
'ISO-8859-1',
'UTF-8',$currency);
747 $space = $locale[
"{$letter}_sep_by_space"] ?
' ' :
'';
749 $number = number_format($number, $right, $locale[
'mon_decimal_point'], $flags[
'nogroup'] ?
'' : $locale[
'mon_thousands_sep'] );
750 $number = explode($locale[
'mon_decimal_point'], $number);
752 $n = strlen($prefix) + strlen($currency);
753 if ($left > 0 && $left > $n) {
754 if ($flags[
'isleft']) {
755 $number[0] .= str_repeat($flags[
'fillchar'], $left - $n);
757 $number[0] = str_repeat($flags[
'fillchar'], $left - $n) . $number[0];
760 $number = implode($locale[
'mon_decimal_point'], $number);
761 if ($locale[
"{$letter}_cs_precedes"]) {
762 $number = $prefix . $currency .
$space . $number . $suffix;
764 $number = $prefix . $number .
$space . $currency . $suffix;
767 $number = str_pad($number, $width, $flags[
'fillchar'], $flags[
'isleft'] ? STR_PAD_RIGHT : STR_PAD_LEFT);
769 $format = str_replace($fmatch[0], $number, $format);
779 if ((!function_exists(
'mb_str_replace')) &&
780 (function_exists(
'mb_substr')) && (function_exists(
'mb_strlen')) && (function_exists(
'mb_strpos'))) {
781 function mb_str_replace($search, $replace, $subject) {
782 if(is_array($subject)) {
784 foreach($subject as $key => $val) {
785 $ret[$key] = mb_str_replace($search, $replace, $val);
790 foreach((array) $search as $key => $s) {
794 $r = !is_array($replace) ? $replace : (array_key_exists($key, $replace) ? $replace[$key] :
'');
795 $pos = mb_strpos($subject, $s, 0,
'UTF-8');
796 while(
$pos !==
false) {
797 $subject = mb_substr($subject, 0,
$pos,
'UTF-8') . $r . mb_substr($subject,
$pos + mb_strlen($s,
'UTF-8'), 65535,
'UTF-8');
798 $pos = mb_strpos($subject, $s,
$pos + mb_strlen($r,
'UTF-8'),
'UTF-8');