34        define(
'PHPEXCEL_ROOT', dirname(__FILE__) . 
'/../../');
 
   35        require(PHPEXCEL_ROOT . 
'PHPExcel/Autoloader.php');
 
   52                $startVal = floor(sqrt($value));
 
   54                $factorArray = array();
 
   55                for (
$i = $startVal; 
$i > 1; --
$i) {
 
   56                        if (($value % 
$i) == 0) {
 
   57                                $factorArray = array_merge($factorArray,self::_factors($value / 
$i));
 
   58                                $factorArray = array_merge($factorArray,self::_factors(
$i));
 
   59                                if (
$i <= sqrt($value)) {
 
   64                if (!empty($factorArray)) {
 
   68                        return array((integer) $value);
 
   74                return ($num - ($num % 
$n ) ) / 
$n;
 
  100        public static function ATAN2($xCoordinate = NULL, $yCoordinate = NULL) {
 
  104                $xCoordinate    = ($xCoordinate !== NULL)       ? $xCoordinate : 0.0;
 
  105                $yCoordinate    = ($yCoordinate !== NULL)       ? $yCoordinate : 0.0;
 
  107                if (((is_numeric($xCoordinate)) || (is_bool($xCoordinate))) &&
 
  108                        ((is_numeric($yCoordinate)))  || (is_bool($yCoordinate))) {
 
  109                        $xCoordinate    = (float) $xCoordinate;
 
  110                        $yCoordinate    = (float) $yCoordinate;
 
  112                        if (($xCoordinate == 0) && ($yCoordinate == 0)) {
 
  116                        return atan2($yCoordinate, $xCoordinate);
 
  139        public static function CEILING($number, $significance = NULL) {
 
  143                if ((is_null($significance)) &&
 
  145                        $significance = $number/abs($number);
 
  148        if ((is_numeric($number)) && (is_numeric($significance))) {
 
  149            if (($number == 0.0 ) || ($significance == 0.0)) {
 
  151                        } elseif (self::SIGN($number) == self::SIGN($significance)) {
 
  152                                return ceil($number / $significance) * $significance;
 
  176        public static function COMBIN($numObjs, $numInSet) {
 
  180                if ((is_numeric($numObjs)) && (is_numeric($numInSet))) {
 
  181                        if ($numObjs < $numInSet) {
 
  183                        } elseif ($numInSet < 0) {
 
  186                        return round(self::FACT($numObjs) / self::FACT($numObjs - $numInSet)) / 
self::FACT($numInSet);
 
  209        public static function EVEN($number) {
 
  212                if (is_null($number)) {
 
  214                } elseif (is_bool($number)) {
 
  215                        $number = (int) $number;
 
  218                if (is_numeric($number)) {
 
  240        public static function FACT($factVal) {
 
  243                if (is_numeric($factVal)) {
 
  247                        $factLoop = floor($factVal);
 
  249                                if ($factVal > $factLoop) {
 
  255                        while ($factLoop > 1) {
 
  256                                $factorial *= $factLoop--;
 
  280                if (is_numeric($factLoop)) {
 
  281                        $factLoop       = floor($factLoop);
 
  286                        while ($factLoop > 1) {
 
  287                                $factorial *= $factLoop--;
 
  310        public static function FLOOR($number, $significance = NULL) {
 
  315                        $significance = $number/abs($number);
 
  318                if ((is_numeric($number)) && (is_numeric($significance))) {
 
  319            if ($significance == 0.0) {
 
  321            } elseif ($number == 0.0) {
 
  323                        } elseif (self::SIGN($number) == self::SIGN($significance)) {
 
  324                                return floor($number / $significance) * $significance;
 
  349        public static function GCD() {
 
  351                $allValuesFactors = array();
 
  354                        if (!is_numeric($value)) {
 
  356                        } elseif ($value == 0) {
 
  358                        } elseif($value < 0) {
 
  362                        $myCountedFactors = array_count_values($myFactors);
 
  363                        $allValuesFactors[] = $myCountedFactors;
 
  365                $allValuesCount = count($allValuesFactors);
 
  366                if ($allValuesCount == 0) {
 
  370                $mergedArray = $allValuesFactors[0];
 
  371                for (
$i=1;
$i < $allValuesCount; ++
$i) {
 
  372                        $mergedArray = array_intersect_key($mergedArray,$allValuesFactors[
$i]);
 
  374                $mergedArrayValues = count($mergedArray);
 
  375                if ($mergedArrayValues == 0) {
 
  377                } elseif ($mergedArrayValues > 1) {
 
  378                        foreach($mergedArray as $mergedKey => $mergedValue) {
 
  379                                foreach($allValuesFactors as $highestPowerTest) {
 
  380                                        foreach($highestPowerTest as $testKey => $testValue) {
 
  381                                                if (($testKey == $mergedKey) && ($testValue < $mergedValue)) {
 
  382                                                        $mergedArray[$mergedKey] = $testValue;
 
  383                                                        $mergedValue = $testValue;
 
  390                        foreach($mergedArray as 
$key => $value) {
 
  391                                $returnValue *= pow(
$key,$value);
 
  395                        $keys = array_keys($mergedArray);
 
  397                        $value = $mergedArray[
$key];
 
  398                        foreach($allValuesFactors as $testValue) {
 
  399                                foreach($testValue as $mergedKey => $mergedValue) {
 
  400                                        if (($mergedKey == 
$key) && ($mergedValue < $value)) {
 
  401                                                $value = $mergedValue;
 
  405                        return pow(
$key,$value);
 
  423        public static function INT($number) {
 
  426                if (is_null($number)) {
 
  428                } elseif (is_bool($number)) {
 
  429                        return (
int) $number;
 
  431                if (is_numeric($number)) {
 
  432                        return (
int) floor($number);
 
  454        public static function LCM() {
 
  456                $allPoweredFactors = array();
 
  459                        if (!is_numeric($value)) {
 
  464                        } elseif ($value < 0) {
 
  468                        $myCountedFactors = array_count_values($myFactors);
 
  469                        $myPoweredFactors = array();
 
  470                        foreach($myCountedFactors as $myCountedFactor => $myCountedPower) {
 
  471                                $myPoweredFactors[$myCountedFactor] = pow($myCountedFactor,$myCountedPower);
 
  473                        foreach($myPoweredFactors as $myPoweredValue => $myPoweredFactor) {
 
  474                                if (array_key_exists($myPoweredValue,$allPoweredFactors)) {
 
  475                                        if ($allPoweredFactors[$myPoweredValue] < $myPoweredFactor) {
 
  476                                                $allPoweredFactors[$myPoweredValue] = $myPoweredFactor;
 
  479                                        $allPoweredFactors[$myPoweredValue] = $myPoweredFactor;
 
  483                foreach($allPoweredFactors as $allPoweredFactor) {
 
  484                        $returnValue *= (integer) $allPoweredFactor;
 
  508                if ((!is_numeric(
$base)) || (!is_numeric($number)))
 
  510                if ((
$base <= 0) || ($number <= 0))
 
  512                return log($number, 
$base);
 
  529        public static function MDETERM($matrixValues) {
 
  530                $matrixData = array();
 
  531                if (!is_array($matrixValues)) { $matrixValues = array(array($matrixValues)); }
 
  533                $row = $maxColumn = 0;
 
  534                foreach($matrixValues as $matrixRow) {
 
  535                        if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); }
 
  537                        foreach($matrixRow as $matrixCell) {
 
  538                                if ((is_string($matrixCell)) || ($matrixCell === 
null)) {
 
  551                        return $matrix->det();
 
  572                $matrixData = array();
 
  573                if (!is_array($matrixValues)) { $matrixValues = array(array($matrixValues)); }
 
  575                $row = $maxColumn = 0;
 
  576                foreach($matrixValues as $matrixRow) {
 
  577                        if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); }
 
  579                        foreach($matrixRow as $matrixCell) {
 
  580                                if ((is_string($matrixCell)) || ($matrixCell === 
null)) {
 
  593                        return $matrix->inverse()->getArray();
 
  607        public static function MMULT($matrixData1,$matrixData2) {
 
  608                $matrixAData = $matrixBData = array();
 
  609                if (!is_array($matrixData1)) { $matrixData1 = array(array($matrixData1)); }
 
  610                if (!is_array($matrixData2)) { $matrixData2 = array(array($matrixData2)); }
 
  614            foreach($matrixData1 as $matrixRow) {
 
  615                if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); }
 
  617                foreach($matrixRow as $matrixCell) {
 
  618                    if ((!is_numeric($matrixCell)) || ($matrixCell === 
null)) {
 
  621                    $matrixAData[$rowA][$columnA] = $matrixCell;
 
  628                        foreach($matrixData2 as $matrixRow) {
 
  629                                if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); }
 
  631                                foreach($matrixRow as $matrixCell) {
 
  632                                        if ((!is_numeric($matrixCell)) || ($matrixCell === 
null)) {
 
  635                                        $matrixBData[$rowB][$columnB] = $matrixCell;
 
  642                        if ($columnA != $rowB) {
 
  646                        return $matrixA->times($matrixB)->getArray();
 
  648            var_dump($ex->getMessage());
 
  661        public static function MOD($a = 1, $b = 1) {
 
  667                } elseif (($a < 0.0) && ($b > 0.0)) {
 
  668                        return $b - fmod(abs($a),$b);
 
  669                } elseif (($a > 0.0) && ($b < 0.0)) {
 
  670                        return $b + fmod($a,abs($b));
 
  686        public static function MROUND($number,$multiple) {
 
  690                if ((is_numeric($number)) && (is_numeric($multiple))) {
 
  691                        if ($multiple == 0) {
 
  694                        if ((self::SIGN($number)) == (self::SIGN($multiple))) {
 
  695                                $multiplier = 1 / $multiple;
 
  696                                return round($number * $multiplier) / $multiplier;
 
  718                        if (is_numeric($arg)) {
 
  722                                $summer += floor($arg);
 
  732                        return $summer / $divisor;
 
  746        public static function ODD($number) {
 
  749                if (is_null($number)) {
 
  751                } elseif (is_bool($number)) {
 
  752                        $number = (int) $number;
 
  755                if (is_numeric($number)) {
 
  757                        if ($significance == 0) {
 
  786                if (
$x == 0.0 && 
$y == 0.0) {
 
  788                } elseif (
$x == 0.0 && 
$y < 0.0) {
 
  818                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
  819                                if (is_null($returnValue)) {
 
  822                                        $returnValue *= $arg;
 
  828                if (is_null($returnValue)) {
 
  856                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
  857                                if (is_null($returnValue)) {
 
  858                                        $returnValue = ($arg == 0) ? 0 : $arg;
 
  860                                        if (($returnValue == 0) || ($arg == 0)) {
 
  863                                                $returnValue /= $arg;
 
  870                return intval($returnValue);
 
  881        public static function RAND($min = 0, $max = 0) {
 
  885                if ($min == 0 && $max == 0) {
 
  886                        return (mt_rand(0,10000000)) / 10000000;
 
  888                        return mt_rand($min, $max);
 
  896                if ((!is_numeric($aValue)) || ($aValue < 0) || ($aValue >= 4000)) {
 
  899                $aValue = (integer) $aValue;
 
  904                $mill = Array(
'', 
'M', 
'MM', 
'MMM', 
'MMMM', 
'MMMMM');
 
  905                $cent = Array(
'', 
'C', 
'CC', 
'CCC', 
'CD', 
'D', 
'DC', 
'DCC', 
'DCCC', 
'CM');
 
  906                $tens = Array(
'', 
'X', 
'XX', 
'XXX', 
'XL', 
'L', 
'LX', 
'LXX', 
'LXXX', 
'XC');
 
  907                $ones = Array(
'', 
'I', 
'II', 
'III', 
'IV', 
'V', 
'VI', 
'VII', 
'VIII', 
'IX');
 
  910                while ($aValue > 5999) {
 
  918                return $roman.$mill[
$m].$cent[$c].$tens[
$t].$ones[$aValue];
 
  931        public static function ROUNDUP($number,$digits) {
 
  935                if ((is_numeric($number)) && (is_numeric($digits))) {
 
  936                        $significance = pow(10,(
int) $digits);
 
  938                                return floor($number * $significance) / $significance;
 
  940                                return ceil($number * $significance) / $significance;
 
  960                if ((is_numeric($number)) && (is_numeric($digits))) {
 
  961                        $significance = pow(10,(
int) $digits);
 
  963                                return ceil($number * $significance) / $significance;
 
  965                                return floor($number * $significance) / $significance;
 
  990                $x = array_shift($aArgs);
 
  991                $n = array_shift($aArgs);
 
  992                $m = array_shift($aArgs);
 
  994                if ((is_numeric(
$x)) && (is_numeric(
$n)) && (is_numeric(
$m))) {
 
  997                        foreach($aArgs as $arg) {
 
  999                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
 1000                                        $returnValue += $arg * pow(
$x,
$n + (
$m * 
$i++));
 
 1006                        return $returnValue;
 
 1021        public static function SIGN($number) {
 
 1024                if (is_bool($number))
 
 1025                        return (
int) $number;
 
 1026                if (is_numeric($number)) {
 
 1027                        if ($number == 0.0) {
 
 1030                        return $number / abs($number);
 
 1047                if (is_numeric($number)) {
 
 1051                        return sqrt($number * M_PI) ;
 
 1071                $subtotal = array_shift($aArgs);
 
 1073                if ((is_numeric($subtotal)) && (!is_string($subtotal))) {
 
 1127        public static function SUM() {
 
 1134                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 1135                                $returnValue += $arg;
 
 1140                return $returnValue;
 
 1158        public static function SUMIF($aArgs,$condition,$sumArgs = array()) {
 
 1164                if (empty($sumArgs)) {
 
 1169                foreach ($aArgs as 
$key => $arg) {
 
 1170                        if (!is_numeric($arg)) {
 
 1171                                $arg = str_replace(
'"', 
'""', $arg);
 
 1175                        $testCondition = 
'='.$arg.$condition;
 
 1178                                $returnValue += $sumArgs[
$key];
 
 1183                return $returnValue;
 
 1199                $arrayList = func_get_args();
 
 1202                $wrkCellCount = count($wrkArray);
 
 1204                for (
$i=0; 
$i< $wrkCellCount; ++
$i) {
 
 1205                        if ((!is_numeric($wrkArray[
$i])) || (is_string($wrkArray[
$i]))) {
 
 1210                foreach($arrayList as $matrixData) {
 
 1212                        $count = count($array2);
 
 1213                        if ($wrkCellCount != $count) {
 
 1217                        foreach ($array2 as 
$i => $val) {
 
 1218                                if ((!is_numeric($val)) || (is_string($val))) {
 
 1221                                $wrkArray[
$i] *= $val;
 
 1225                return array_sum($wrkArray);
 
 1249                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 1250                                $returnValue += ($arg * $arg);
 
 1255                return $returnValue;
 
 1266        public static function SUMX2MY2($matrixData1,$matrixData2) {
 
 1269                $count1 = count($array1);
 
 1270                $count2 = count($array2);
 
 1271                if ($count1 < $count2) {
 
 1278                for (
$i = 0; 
$i < $count; ++
$i) {
 
 1279                        if (((is_numeric($array1[
$i])) && (!is_string($array1[
$i]))) &&
 
 1280                                ((is_numeric($array2[
$i])) && (!is_string($array2[
$i])))) {
 
 1296        public static function SUMX2PY2($matrixData1,$matrixData2) {
 
 1299                $count1 = count($array1);
 
 1300                $count2 = count($array2);
 
 1301                if ($count1 < $count2) {
 
 1308                for (
$i = 0; 
$i < $count; ++
$i) {
 
 1309                        if (((is_numeric($array1[
$i])) && (!is_string($array1[
$i]))) &&
 
 1310                                ((is_numeric($array2[
$i])) && (!is_string($array2[
$i])))) {
 
 1326        public static function SUMXMY2($matrixData1,$matrixData2) {
 
 1329                $count1 = count($array1);
 
 1330                $count2 = count($array2);
 
 1331                if ($count1 < $count2) {
 
 1338                for (
$i = 0; 
$i < $count; ++
$i) {
 
 1339                        if (((is_numeric($array1[
$i])) && (!is_string($array1[
$i]))) &&
 
 1340                                ((is_numeric($array2[
$i])) && (!is_string($array2[
$i])))) {
 
 1358        public static function TRUNC($value = 0, $digits = 0) {
 
 1363                if ((!is_numeric($value)) || (!is_numeric($digits)))
 
 1365                $digits = floor($digits);
 
 1368                $adjust = pow(10, $digits);
 
 1370                if (($digits > 0) && (rtrim(intval((abs($value) - abs(intval($value))) * $adjust),
'0') < $adjust/10))
 
 1373                return (intval($value * $adjust)) / $adjust;
 
An exception for terminatinating execution or to throw for unit testing.
static getCompatibilityMode()
static _ifCondition($condition)
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
const COMPATIBILITY_GNUMERIC
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
static MOD($a=1, $b=1)
MOD.
static TRUNC($value=0, $digits=0)
TRUNC.
static _romanCut($num, $n)
static ATAN2($xCoordinate=NULL, $yCoordinate=NULL)
static POWER($x=0, $y=2)
POWER.
static LOG_BASE($number=NULL, $base=10)
static MDETERM($matrixValues)
static SUMX2MY2($matrixData1, $matrixData2)
SUMX2MY2.
static MMULT($matrixData1, $matrixData2)
MMULT.
static SUBTOTAL()
SUBTOTAL.
static SERIESSUM()
SERIESSUM.
static ROUNDDOWN($number, $digits)
ROUNDDOWN.
static MROUND($number, $multiple)
MROUND.
static SUMIF($aArgs, $condition, $sumArgs=array())
static SQRTPI($number)
SQRTPI.
static FLOOR($number, $significance=NULL)
static SUMX2PY2($matrixData1, $matrixData2)
SUMX2PY2.
static CEILING($number, $significance=NULL)
static MINVERSE($matrixValues)
static FACTDOUBLE($factVal)
static RAND($min=0, $max=0)
RAND.
static COMBIN($numObjs, $numInSet)
static MULTINOMIAL()
MULTINOMIAL.
static SUMXMY2($matrixData1, $matrixData2)
SUMXMY2.
static ROMAN($aValue, $style=0)
static ROUNDUP($number, $digits)
ROUNDUP.
static SIGN($number)
SIGN.
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
static _wrapResult($value)
Wrap string values in quotes.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'