Directory access is forbidden.
PK ! m,C C " PHPExcel/Calculation/Functions.phpnu [ '#NULL!', 'divisionbyzero' => '#DIV/0!', 'value' => '#VALUE!', 'reference' => '#REF!', 'name' => '#NAME?', 'num' => '#NUM!', 'na' => '#N/A', 'gettingdata' => '#GETTING_DATA' ); /** * Set the Compatibility Mode * * @access public * @category Function Configuration * @param string $compatibilityMode Compatibility Mode * Permitted values are: * PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL 'Excel' * PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' * PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' * @return boolean (Success or Failure) */ public static function setCompatibilityMode($compatibilityMode) { if (($compatibilityMode == self::COMPATIBILITY_EXCEL) || ($compatibilityMode == self::COMPATIBILITY_GNUMERIC) || ($compatibilityMode == self::COMPATIBILITY_OPENOFFICE)) { self::$compatibilityMode = $compatibilityMode; return True; } return False; } // function setCompatibilityMode() /** * Return the current Compatibility Mode * * @access public * @category Function Configuration * @return string Compatibility Mode * Possible Return values are: * PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL 'Excel' * PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' * PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' */ public static function getCompatibilityMode() { return self::$compatibilityMode; } // function getCompatibilityMode() /** * Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object) * * @access public * @category Function Configuration * @param string $returnDateType Return Date Format * Permitted values are: * PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC 'P' * PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT 'O' * PHPExcel_Calculation_Functions::RETURNDATE_EXCEL 'E' * @return boolean Success or failure */ public static function setReturnDateType($returnDateType) { if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) || ($returnDateType == self::RETURNDATE_PHP_OBJECT) || ($returnDateType == self::RETURNDATE_EXCEL)) { self::$ReturnDateType = $returnDateType; return True; } return False; } // function setReturnDateType() /** * Return the current Return Date Format for functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object) * * @access public * @category Function Configuration * @return string Return Date Format * Possible Return values are: * PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC 'P' * PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT 'O' * PHPExcel_Calculation_Functions::RETURNDATE_EXCEL 'E' */ public static function getReturnDateType() { return self::$ReturnDateType; } // function getReturnDateType() /** * DUMMY * * @access public * @category Error Returns * @return string #Not Yet Implemented */ public static function DUMMY() { return '#Not Yet Implemented'; } // function DUMMY() /** * DIV0 * * @access public * @category Error Returns * @return string #Not Yet Implemented */ public static function DIV0() { return self::$_errorCodes['divisionbyzero']; } // function DIV0() /** * NA * * Excel Function: * =NA() * * Returns the error value #N/A * #N/A is the error value that means "no value is available." * * @access public * @category Logical Functions * @return string #N/A! */ public static function NA() { return self::$_errorCodes['na']; } // function NA() /** * NaN * * Returns the error value #NUM! * * @access public * @category Error Returns * @return string #NUM! */ public static function NaN() { return self::$_errorCodes['num']; } // function NaN() /** * NAME * * Returns the error value #NAME? * * @access public * @category Error Returns * @return string #NAME? */ public static function NAME() { return self::$_errorCodes['name']; } // function NAME() /** * REF * * Returns the error value #REF! * * @access public * @category Error Returns * @return string #REF! */ public static function REF() { return self::$_errorCodes['reference']; } // function REF() /** * NULL * * Returns the error value #NULL! * * @access public * @category Error Returns * @return string #NULL! */ public static function NULL() { return self::$_errorCodes['null']; } // function NULL() /** * VALUE * * Returns the error value #VALUE! * * @access public * @category Error Returns * @return string #VALUE! */ public static function VALUE() { return self::$_errorCodes['value']; } // function VALUE() public static function isMatrixValue($idx) { return ((substr_count($idx,'.') <= 1) || (preg_match('/\.[A-Z]/',$idx) > 0)); } public static function isValue($idx) { return (substr_count($idx,'.') == 0); } public static function isCellValue($idx) { return (substr_count($idx,'.') > 1); } public static function _ifCondition($condition) { $condition = PHPExcel_Calculation_Functions::flattenSingleValue($condition); if (!isset($condition{0})) $condition = '=""'; if (!in_array($condition{0},array('>', '<', '='))) { if (!is_numeric($condition)) { $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); } return '='.$condition; } else { preg_match('/([<>=]+)(.*)/',$condition,$matches); list(,$operator,$operand) = $matches; if (!is_numeric($operand)) { $operand = str_replace('"', '""', $operand); $operand = PHPExcel_Calculation::_wrapResult(strtoupper($operand)); } return $operator.$operand; } } // function _ifCondition() /** * ERROR_TYPE * * @param mixed $value Value to check * @return boolean */ public static function ERROR_TYPE($value = '') { $value = self::flattenSingleValue($value); $i = 1; foreach(self::$_errorCodes as $errorCode) { if ($value === $errorCode) { return $i; } ++$i; } return self::NA(); } // function ERROR_TYPE() /** * IS_BLANK * * @param mixed $value Value to check * @return boolean */ public static function IS_BLANK($value = NULL) { if (!is_null($value)) { $value = self::flattenSingleValue($value); } return is_null($value); } // function IS_BLANK() /** * IS_ERR * * @param mixed $value Value to check * @return boolean */ public static function IS_ERR($value = '') { $value = self::flattenSingleValue($value); return self::IS_ERROR($value) && (!self::IS_NA($value)); } // function IS_ERR() /** * IS_ERROR * * @param mixed $value Value to check * @return boolean */ public static function IS_ERROR($value = '') { $value = self::flattenSingleValue($value); if (!is_string($value)) return false; return in_array($value, array_values(self::$_errorCodes)); } // function IS_ERROR() /** * IS_NA * * @param mixed $value Value to check * @return boolean */ public static function IS_NA($value = '') { $value = self::flattenSingleValue($value); return ($value === self::NA()); } // function IS_NA() /** * IS_EVEN * * @param mixed $value Value to check * @return boolean */ public static function IS_EVEN($value = NULL) { $value = self::flattenSingleValue($value); if ($value === NULL) return self::NAME(); if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) return self::VALUE(); return ($value % 2 == 0); } // function IS_EVEN() /** * IS_ODD * * @param mixed $value Value to check * @return boolean */ public static function IS_ODD($value = NULL) { $value = self::flattenSingleValue($value); if ($value === NULL) return self::NAME(); if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) return self::VALUE(); return (abs($value) % 2 == 1); } // function IS_ODD() /** * IS_NUMBER * * @param mixed $value Value to check * @return boolean */ public static function IS_NUMBER($value = NULL) { $value = self::flattenSingleValue($value); if (is_string($value)) { return False; } return is_numeric($value); } // function IS_NUMBER() /** * IS_LOGICAL * * @param mixed $value Value to check * @return boolean */ public static function IS_LOGICAL($value = NULL) { $value = self::flattenSingleValue($value); return is_bool($value); } // function IS_LOGICAL() /** * IS_TEXT * * @param mixed $value Value to check * @return boolean */ public static function IS_TEXT($value = NULL) { $value = self::flattenSingleValue($value); return (is_string($value) && !self::IS_ERROR($value)); } // function IS_TEXT() /** * IS_NONTEXT * * @param mixed $value Value to check * @return boolean */ public static function IS_NONTEXT($value = NULL) { return !self::IS_TEXT($value); } // function IS_NONTEXT() /** * VERSION * * @return string Version information */ public static function VERSION() { return 'PHPExcel 1.8.0, 2014-03-02'; } // function VERSION() /** * N * * Returns a value converted to a number * * @param value The value you want converted * @return number N converts values listed in the following table * If value is or refers to N returns * A number That number * A date The serial number of that date * TRUE 1 * FALSE 0 * An error value The error value * Anything else 0 */ public static function N($value = NULL) { while (is_array($value)) { $value = array_shift($value); } switch (gettype($value)) { case 'double' : case 'float' : case 'integer' : return $value; break; case 'boolean' : return (integer) $value; break; case 'string' : // Errors if ((strlen($value) > 0) && ($value{0} == '#')) { return $value; } break; } return 0; } // function N() /** * TYPE * * Returns a number that identifies the type of a value * * @param value The value you want tested * @return number N converts values listed in the following table * If value is or refers to N returns * A number 1 * Text 2 * Logical Value 4 * An error value 16 * Array or Matrix 64 */ public static function TYPE($value = NULL) { $value = self::flattenArrayIndexed($value); if (is_array($value) && (count($value) > 1)) { $a = array_keys($value); $a = array_pop($a); // Range of cells is an error if (self::isCellValue($a)) { return 16; // Test for Matrix } elseif (self::isMatrixValue($a)) { return 64; } } elseif(empty($value)) { // Empty Cell return 1; } $value = self::flattenSingleValue($value); if (($value === NULL) || (is_float($value)) || (is_int($value))) { return 1; } elseif(is_bool($value)) { return 4; } elseif(is_array($value)) { return 64; break; } elseif(is_string($value)) { // Errors if ((strlen($value) > 0) && ($value{0} == '#')) { return 16; } return 2; } return 0; } // function TYPE() /** * Convert a multi-dimensional array to a simple 1-dimensional array * * @param array $array Array to be flattened * @return array Flattened array */ public static function flattenArray($array) { if (!is_array($array)) { return (array) $array; } $arrayValues = array(); foreach ($array as $value) { if (is_array($value)) { foreach ($value as $val) { if (is_array($val)) { foreach ($val as $v) { $arrayValues[] = $v; } } else { $arrayValues[] = $val; } } } else { $arrayValues[] = $value; } } return $arrayValues; } // function flattenArray() /** * Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing * * @param array $array Array to be flattened * @return array Flattened array */ public static function flattenArrayIndexed($array) { if (!is_array($array)) { return (array) $array; } $arrayValues = array(); foreach ($array as $k1 => $value) { if (is_array($value)) { foreach ($value as $k2 => $val) { if (is_array($val)) { foreach ($val as $k3 => $v) { $arrayValues[$k1.'.'.$k2.'.'.$k3] = $v; } } else { $arrayValues[$k1.'.'.$k2] = $val; } } } else { $arrayValues[$k1] = $value; } } return $arrayValues; } // function flattenArrayIndexed() /** * Convert an array to a single scalar value by extracting the first element * * @param mixed $value Array or scalar value * @return mixed */ public static function flattenSingleValue($value = '') { while (is_array($value)) { $value = array_pop($value); } return $value; } // function flattenSingleValue() } // class PHPExcel_Calculation_Functions // // There are a few mathematical functions that aren't available on all versions of PHP for all platforms // These functions aren't available in Windows implementations of PHP prior to version 5.3.0 // So we test if they do exist for this version of PHP/operating platform; and if not we create them // if (!function_exists('acosh')) { function acosh($x) { return 2 * log(sqrt(($x + 1) / 2) + sqrt(($x - 1) / 2)); } // function acosh() } if (!function_exists('asinh')) { function asinh($x) { return log($x + sqrt(1 + $x * $x)); } // function asinh() } if (!function_exists('atanh')) { function atanh($x) { return (log(1 + $x) - log(1 - $x)) / 2; } // function atanh() } // // Strangely, PHP doesn't have a mb_str_replace multibyte function // As we'll only ever use this function with UTF-8 characters, we can simply "hard-code" the character set // if ((!function_exists('mb_str_replace')) && (function_exists('mb_substr')) && (function_exists('mb_strlen')) && (function_exists('mb_strpos'))) { function mb_str_replace($search, $replace, $subject) { if(is_array($subject)) { $ret = array(); foreach($subject as $key => $val) { $ret[$key] = mb_str_replace($search, $replace, $val); } return $ret; } foreach((array) $search as $key => $s) { if($s == '') { continue; } $r = !is_array($replace) ? $replace : (array_key_exists($key, $replace) ? $replace[$key] : ''); $pos = mb_strpos($subject, $s, 0, 'UTF-8'); while($pos !== false) { $subject = mb_substr($subject, 0, $pos, 'UTF-8') . $r . mb_substr($subject, $pos + mb_strlen($s, 'UTF-8'), 65535, 'UTF-8'); $pos = mb_strpos($subject, $s, $pos + mb_strlen($r, 'UTF-8'), 'UTF-8'); } } return $subject; } } PK ! 08}ށ $ PHPExcel/Calculation/Engineering.phpnu [ array( 'Group' => 'Mass', 'Unit Name' => 'Gram', 'AllowPrefix' => True ), 'sg' => array( 'Group' => 'Mass', 'Unit Name' => 'Slug', 'AllowPrefix' => False ), 'lbm' => array( 'Group' => 'Mass', 'Unit Name' => 'Pound mass (avoirdupois)', 'AllowPrefix' => False ), 'u' => array( 'Group' => 'Mass', 'Unit Name' => 'U (atomic mass unit)', 'AllowPrefix' => True ), 'ozm' => array( 'Group' => 'Mass', 'Unit Name' => 'Ounce mass (avoirdupois)', 'AllowPrefix' => False ), 'm' => array( 'Group' => 'Distance', 'Unit Name' => 'Meter', 'AllowPrefix' => True ), 'mi' => array( 'Group' => 'Distance', 'Unit Name' => 'Statute mile', 'AllowPrefix' => False ), 'Nmi' => array( 'Group' => 'Distance', 'Unit Name' => 'Nautical mile', 'AllowPrefix' => False ), 'in' => array( 'Group' => 'Distance', 'Unit Name' => 'Inch', 'AllowPrefix' => False ), 'ft' => array( 'Group' => 'Distance', 'Unit Name' => 'Foot', 'AllowPrefix' => False ), 'yd' => array( 'Group' => 'Distance', 'Unit Name' => 'Yard', 'AllowPrefix' => False ), 'ang' => array( 'Group' => 'Distance', 'Unit Name' => 'Angstrom', 'AllowPrefix' => True ), 'Pica' => array( 'Group' => 'Distance', 'Unit Name' => 'Pica (1/72 in)', 'AllowPrefix' => False ), 'yr' => array( 'Group' => 'Time', 'Unit Name' => 'Year', 'AllowPrefix' => False ), 'day' => array( 'Group' => 'Time', 'Unit Name' => 'Day', 'AllowPrefix' => False ), 'hr' => array( 'Group' => 'Time', 'Unit Name' => 'Hour', 'AllowPrefix' => False ), 'mn' => array( 'Group' => 'Time', 'Unit Name' => 'Minute', 'AllowPrefix' => False ), 'sec' => array( 'Group' => 'Time', 'Unit Name' => 'Second', 'AllowPrefix' => True ), 'Pa' => array( 'Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => True ), 'p' => array( 'Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => True ), 'atm' => array( 'Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => True ), 'at' => array( 'Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => True ), 'mmHg' => array( 'Group' => 'Pressure', 'Unit Name' => 'mm of Mercury', 'AllowPrefix' => True ), 'N' => array( 'Group' => 'Force', 'Unit Name' => 'Newton', 'AllowPrefix' => True ), 'dyn' => array( 'Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => True ), 'dy' => array( 'Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => True ), 'lbf' => array( 'Group' => 'Force', 'Unit Name' => 'Pound force', 'AllowPrefix' => False ), 'J' => array( 'Group' => 'Energy', 'Unit Name' => 'Joule', 'AllowPrefix' => True ), 'e' => array( 'Group' => 'Energy', 'Unit Name' => 'Erg', 'AllowPrefix' => True ), 'c' => array( 'Group' => 'Energy', 'Unit Name' => 'Thermodynamic calorie', 'AllowPrefix' => True ), 'cal' => array( 'Group' => 'Energy', 'Unit Name' => 'IT calorie', 'AllowPrefix' => True ), 'eV' => array( 'Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => True ), 'ev' => array( 'Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => True ), 'HPh' => array( 'Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => False ), 'hh' => array( 'Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => False ), 'Wh' => array( 'Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => True ), 'wh' => array( 'Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => True ), 'flb' => array( 'Group' => 'Energy', 'Unit Name' => 'Foot-pound', 'AllowPrefix' => False ), 'BTU' => array( 'Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => False ), 'btu' => array( 'Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => False ), 'HP' => array( 'Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => False ), 'h' => array( 'Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => False ), 'W' => array( 'Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => True ), 'w' => array( 'Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => True ), 'T' => array( 'Group' => 'Magnetism', 'Unit Name' => 'Tesla', 'AllowPrefix' => True ), 'ga' => array( 'Group' => 'Magnetism', 'Unit Name' => 'Gauss', 'AllowPrefix' => True ), 'C' => array( 'Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => False ), 'cel' => array( 'Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => False ), 'F' => array( 'Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => False ), 'fah' => array( 'Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => False ), 'K' => array( 'Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => False ), 'kel' => array( 'Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => False ), 'tsp' => array( 'Group' => 'Liquid', 'Unit Name' => 'Teaspoon', 'AllowPrefix' => False ), 'tbs' => array( 'Group' => 'Liquid', 'Unit Name' => 'Tablespoon', 'AllowPrefix' => False ), 'oz' => array( 'Group' => 'Liquid', 'Unit Name' => 'Fluid Ounce', 'AllowPrefix' => False ), 'cup' => array( 'Group' => 'Liquid', 'Unit Name' => 'Cup', 'AllowPrefix' => False ), 'pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => False ), 'us_pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => False ), 'uk_pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.K. Pint', 'AllowPrefix' => False ), 'qt' => array( 'Group' => 'Liquid', 'Unit Name' => 'Quart', 'AllowPrefix' => False ), 'gal' => array( 'Group' => 'Liquid', 'Unit Name' => 'Gallon', 'AllowPrefix' => False ), 'l' => array( 'Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => True ), 'lt' => array( 'Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => True ) ); /** * Details of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM() * * @var mixed[] */ private static $_conversionMultipliers = array( 'Y' => array( 'multiplier' => 1E24, 'name' => 'yotta' ), 'Z' => array( 'multiplier' => 1E21, 'name' => 'zetta' ), 'E' => array( 'multiplier' => 1E18, 'name' => 'exa' ), 'P' => array( 'multiplier' => 1E15, 'name' => 'peta' ), 'T' => array( 'multiplier' => 1E12, 'name' => 'tera' ), 'G' => array( 'multiplier' => 1E9, 'name' => 'giga' ), 'M' => array( 'multiplier' => 1E6, 'name' => 'mega' ), 'k' => array( 'multiplier' => 1E3, 'name' => 'kilo' ), 'h' => array( 'multiplier' => 1E2, 'name' => 'hecto' ), 'e' => array( 'multiplier' => 1E1, 'name' => 'deka' ), 'd' => array( 'multiplier' => 1E-1, 'name' => 'deci' ), 'c' => array( 'multiplier' => 1E-2, 'name' => 'centi' ), 'm' => array( 'multiplier' => 1E-3, 'name' => 'milli' ), 'u' => array( 'multiplier' => 1E-6, 'name' => 'micro' ), 'n' => array( 'multiplier' => 1E-9, 'name' => 'nano' ), 'p' => array( 'multiplier' => 1E-12, 'name' => 'pico' ), 'f' => array( 'multiplier' => 1E-15, 'name' => 'femto' ), 'a' => array( 'multiplier' => 1E-18, 'name' => 'atto' ), 'z' => array( 'multiplier' => 1E-21, 'name' => 'zepto' ), 'y' => array( 'multiplier' => 1E-24, 'name' => 'yocto' ) ); /** * Details of the Units of measure conversion factors, organised by group * * @var mixed[] */ private static $_unitConversions = array( 'Mass' => array( 'g' => array( 'g' => 1.0, 'sg' => 6.85220500053478E-05, 'lbm' => 2.20462291469134E-03, 'u' => 6.02217000000000E+23, 'ozm' => 3.52739718003627E-02 ), 'sg' => array( 'g' => 1.45938424189287E+04, 'sg' => 1.0, 'lbm' => 3.21739194101647E+01, 'u' => 8.78866000000000E+27, 'ozm' => 5.14782785944229E+02 ), 'lbm' => array( 'g' => 4.5359230974881148E+02, 'sg' => 3.10810749306493E-02, 'lbm' => 1.0, 'u' => 2.73161000000000E+26, 'ozm' => 1.60000023429410E+01 ), 'u' => array( 'g' => 1.66053100460465E-24, 'sg' => 1.13782988532950E-28, 'lbm' => 3.66084470330684E-27, 'u' => 1.0, 'ozm' => 5.85735238300524E-26 ), 'ozm' => array( 'g' => 2.83495152079732E+01, 'sg' => 1.94256689870811E-03, 'lbm' => 6.24999908478882E-02, 'u' => 1.70725600000000E+25, 'ozm' => 1.0 ) ), 'Distance' => array( 'm' => array( 'm' => 1.0, 'mi' => 6.21371192237334E-04, 'Nmi' => 5.39956803455724E-04, 'in' => 3.93700787401575E+01, 'ft' => 3.28083989501312E+00, 'yd' => 1.09361329797891E+00, 'ang' => 1.00000000000000E+10, 'Pica' => 2.83464566929116E+03 ), 'mi' => array( 'm' => 1.60934400000000E+03, 'mi' => 1.0, 'Nmi' => 8.68976241900648E-01, 'in' => 6.33600000000000E+04, 'ft' => 5.28000000000000E+03, 'yd' => 1.76000000000000E+03, 'ang' => 1.60934400000000E+13, 'Pica' => 4.56191999999971E+06 ), 'Nmi' => array( 'm' => 1.85200000000000E+03, 'mi' => 1.15077944802354E+00, 'Nmi' => 1.0, 'in' => 7.29133858267717E+04, 'ft' => 6.07611548556430E+03, 'yd' => 2.02537182785694E+03, 'ang' => 1.85200000000000E+13, 'Pica' => 5.24976377952723E+06 ), 'in' => array( 'm' => 2.54000000000000E-02, 'mi' => 1.57828282828283E-05, 'Nmi' => 1.37149028077754E-05, 'in' => 1.0, 'ft' => 8.33333333333333E-02, 'yd' => 2.77777777686643E-02, 'ang' => 2.54000000000000E+08, 'Pica' => 7.19999999999955E+01 ), 'ft' => array( 'm' => 3.04800000000000E-01, 'mi' => 1.89393939393939E-04, 'Nmi' => 1.64578833693305E-04, 'in' => 1.20000000000000E+01, 'ft' => 1.0, 'yd' => 3.33333333223972E-01, 'ang' => 3.04800000000000E+09, 'Pica' => 8.63999999999946E+02 ), 'yd' => array( 'm' => 9.14400000300000E-01, 'mi' => 5.68181818368230E-04, 'Nmi' => 4.93736501241901E-04, 'in' => 3.60000000118110E+01, 'ft' => 3.00000000000000E+00, 'yd' => 1.0, 'ang' => 9.14400000300000E+09, 'Pica' => 2.59200000085023E+03 ), 'ang' => array( 'm' => 1.00000000000000E-10, 'mi' => 6.21371192237334E-14, 'Nmi' => 5.39956803455724E-14, 'in' => 3.93700787401575E-09, 'ft' => 3.28083989501312E-10, 'yd' => 1.09361329797891E-10, 'ang' => 1.0, 'Pica' => 2.83464566929116E-07 ), 'Pica' => array( 'm' => 3.52777777777800E-04, 'mi' => 2.19205948372629E-07, 'Nmi' => 1.90484761219114E-07, 'in' => 1.38888888888898E-02, 'ft' => 1.15740740740748E-03, 'yd' => 3.85802469009251E-04, 'ang' => 3.52777777777800E+06, 'Pica' => 1.0 ) ), 'Time' => array( 'yr' => array( 'yr' => 1.0, 'day' => 365.25, 'hr' => 8766.0, 'mn' => 525960.0, 'sec' => 31557600.0 ), 'day' => array( 'yr' => 2.73785078713210E-03, 'day' => 1.0, 'hr' => 24.0, 'mn' => 1440.0, 'sec' => 86400.0 ), 'hr' => array( 'yr' => 1.14077116130504E-04, 'day' => 4.16666666666667E-02, 'hr' => 1.0, 'mn' => 60.0, 'sec' => 3600.0 ), 'mn' => array( 'yr' => 1.90128526884174E-06, 'day' => 6.94444444444444E-04, 'hr' => 1.66666666666667E-02, 'mn' => 1.0, 'sec' => 60.0 ), 'sec' => array( 'yr' => 3.16880878140289E-08, 'day' => 1.15740740740741E-05, 'hr' => 2.77777777777778E-04, 'mn' => 1.66666666666667E-02, 'sec' => 1.0 ) ), 'Pressure' => array( 'Pa' => array( 'Pa' => 1.0, 'p' => 1.0, 'atm' => 9.86923299998193E-06, 'at' => 9.86923299998193E-06, 'mmHg' => 7.50061707998627E-03 ), 'p' => array( 'Pa' => 1.0, 'p' => 1.0, 'atm' => 9.86923299998193E-06, 'at' => 9.86923299998193E-06, 'mmHg' => 7.50061707998627E-03 ), 'atm' => array( 'Pa' => 1.01324996583000E+05, 'p' => 1.01324996583000E+05, 'atm' => 1.0, 'at' => 1.0, 'mmHg' => 760.0 ), 'at' => array( 'Pa' => 1.01324996583000E+05, 'p' => 1.01324996583000E+05, 'atm' => 1.0, 'at' => 1.0, 'mmHg' => 760.0 ), 'mmHg' => array( 'Pa' => 1.33322363925000E+02, 'p' => 1.33322363925000E+02, 'atm' => 1.31578947368421E-03, 'at' => 1.31578947368421E-03, 'mmHg' => 1.0 ) ), 'Force' => array( 'N' => array( 'N' => 1.0, 'dyn' => 1.0E+5, 'dy' => 1.0E+5, 'lbf' => 2.24808923655339E-01 ), 'dyn' => array( 'N' => 1.0E-5, 'dyn' => 1.0, 'dy' => 1.0, 'lbf' => 2.24808923655339E-06 ), 'dy' => array( 'N' => 1.0E-5, 'dyn' => 1.0, 'dy' => 1.0, 'lbf' => 2.24808923655339E-06 ), 'lbf' => array( 'N' => 4.448222, 'dyn' => 4.448222E+5, 'dy' => 4.448222E+5, 'lbf' => 1.0 ) ), 'Energy' => array( 'J' => array( 'J' => 1.0, 'e' => 9.99999519343231E+06, 'c' => 2.39006249473467E-01, 'cal' => 2.38846190642017E-01, 'eV' => 6.24145700000000E+18, 'ev' => 6.24145700000000E+18, 'HPh' => 3.72506430801000E-07, 'hh' => 3.72506430801000E-07, 'Wh' => 2.77777916238711E-04, 'wh' => 2.77777916238711E-04, 'flb' => 2.37304222192651E+01, 'BTU' => 9.47815067349015E-04, 'btu' => 9.47815067349015E-04 ), 'e' => array( 'J' => 1.00000048065700E-07, 'e' => 1.0, 'c' => 2.39006364353494E-08, 'cal' => 2.38846305445111E-08, 'eV' => 6.24146000000000E+11, 'ev' => 6.24146000000000E+11, 'HPh' => 3.72506609848824E-14, 'hh' => 3.72506609848824E-14, 'Wh' => 2.77778049754611E-11, 'wh' => 2.77778049754611E-11, 'flb' => 2.37304336254586E-06, 'BTU' => 9.47815522922962E-11, 'btu' => 9.47815522922962E-11 ), 'c' => array( 'J' => 4.18399101363672E+00, 'e' => 4.18398900257312E+07, 'c' => 1.0, 'cal' => 9.99330315287563E-01, 'eV' => 2.61142000000000E+19, 'ev' => 2.61142000000000E+19, 'HPh' => 1.55856355899327E-06, 'hh' => 1.55856355899327E-06, 'Wh' => 1.16222030532950E-03, 'wh' => 1.16222030532950E-03, 'flb' => 9.92878733152102E+01, 'BTU' => 3.96564972437776E-03, 'btu' => 3.96564972437776E-03 ), 'cal' => array( 'J' => 4.18679484613929E+00, 'e' => 4.18679283372801E+07, 'c' => 1.00067013349059E+00, 'cal' => 1.0, 'eV' => 2.61317000000000E+19, 'ev' => 2.61317000000000E+19, 'HPh' => 1.55960800463137E-06, 'hh' => 1.55960800463137E-06, 'Wh' => 1.16299914807955E-03, 'wh' => 1.16299914807955E-03, 'flb' => 9.93544094443283E+01, 'BTU' => 3.96830723907002E-03, 'btu' => 3.96830723907002E-03 ), 'eV' => array( 'J' => 1.60219000146921E-19, 'e' => 1.60218923136574E-12, 'c' => 3.82933423195043E-20, 'cal' => 3.82676978535648E-20, 'eV' => 1.0, 'ev' => 1.0, 'HPh' => 5.96826078912344E-26, 'hh' => 5.96826078912344E-26, 'Wh' => 4.45053000026614E-23, 'wh' => 4.45053000026614E-23, 'flb' => 3.80206452103492E-18, 'BTU' => 1.51857982414846E-22, 'btu' => 1.51857982414846E-22 ), 'ev' => array( 'J' => 1.60219000146921E-19, 'e' => 1.60218923136574E-12, 'c' => 3.82933423195043E-20, 'cal' => 3.82676978535648E-20, 'eV' => 1.0, 'ev' => 1.0, 'HPh' => 5.96826078912344E-26, 'hh' => 5.96826078912344E-26, 'Wh' => 4.45053000026614E-23, 'wh' => 4.45053000026614E-23, 'flb' => 3.80206452103492E-18, 'BTU' => 1.51857982414846E-22, 'btu' => 1.51857982414846E-22 ), 'HPh' => array( 'J' => 2.68451741316170E+06, 'e' => 2.68451612283024E+13, 'c' => 6.41616438565991E+05, 'cal' => 6.41186757845835E+05, 'eV' => 1.67553000000000E+25, 'ev' => 1.67553000000000E+25, 'HPh' => 1.0, 'hh' => 1.0, 'Wh' => 7.45699653134593E+02, 'wh' => 7.45699653134593E+02, 'flb' => 6.37047316692964E+07, 'BTU' => 2.54442605275546E+03, 'btu' => 2.54442605275546E+03 ), 'hh' => array( 'J' => 2.68451741316170E+06, 'e' => 2.68451612283024E+13, 'c' => 6.41616438565991E+05, 'cal' => 6.41186757845835E+05, 'eV' => 1.67553000000000E+25, 'ev' => 1.67553000000000E+25, 'HPh' => 1.0, 'hh' => 1.0, 'Wh' => 7.45699653134593E+02, 'wh' => 7.45699653134593E+02, 'flb' => 6.37047316692964E+07, 'BTU' => 2.54442605275546E+03, 'btu' => 2.54442605275546E+03 ), 'Wh' => array( 'J' => 3.59999820554720E+03, 'e' => 3.59999647518369E+10, 'c' => 8.60422069219046E+02, 'cal' => 8.59845857713046E+02, 'eV' => 2.24692340000000E+22, 'ev' => 2.24692340000000E+22, 'HPh' => 1.34102248243839E-03, 'hh' => 1.34102248243839E-03, 'Wh' => 1.0, 'wh' => 1.0, 'flb' => 8.54294774062316E+04, 'BTU' => 3.41213254164705E+00, 'btu' => 3.41213254164705E+00 ), 'wh' => array( 'J' => 3.59999820554720E+03, 'e' => 3.59999647518369E+10, 'c' => 8.60422069219046E+02, 'cal' => 8.59845857713046E+02, 'eV' => 2.24692340000000E+22, 'ev' => 2.24692340000000E+22, 'HPh' => 1.34102248243839E-03, 'hh' => 1.34102248243839E-03, 'Wh' => 1.0, 'wh' => 1.0, 'flb' => 8.54294774062316E+04, 'BTU' => 3.41213254164705E+00, 'btu' => 3.41213254164705E+00 ), 'flb' => array( 'J' => 4.21400003236424E-02, 'e' => 4.21399800687660E+05, 'c' => 1.00717234301644E-02, 'cal' => 1.00649785509554E-02, 'eV' => 2.63015000000000E+17, 'ev' => 2.63015000000000E+17, 'HPh' => 1.56974211145130E-08, 'hh' => 1.56974211145130E-08, 'Wh' => 1.17055614802000E-05, 'wh' => 1.17055614802000E-05, 'flb' => 1.0, 'BTU' => 3.99409272448406E-05, 'btu' => 3.99409272448406E-05 ), 'BTU' => array( 'J' => 1.05505813786749E+03, 'e' => 1.05505763074665E+10, 'c' => 2.52165488508168E+02, 'cal' => 2.51996617135510E+02, 'eV' => 6.58510000000000E+21, 'ev' => 6.58510000000000E+21, 'HPh' => 3.93015941224568E-04, 'hh' => 3.93015941224568E-04, 'Wh' => 2.93071851047526E-01, 'wh' => 2.93071851047526E-01, 'flb' => 2.50369750774671E+04, 'BTU' => 1.0, 'btu' => 1.0, ), 'btu' => array( 'J' => 1.05505813786749E+03, 'e' => 1.05505763074665E+10, 'c' => 2.52165488508168E+02, 'cal' => 2.51996617135510E+02, 'eV' => 6.58510000000000E+21, 'ev' => 6.58510000000000E+21, 'HPh' => 3.93015941224568E-04, 'hh' => 3.93015941224568E-04, 'Wh' => 2.93071851047526E-01, 'wh' => 2.93071851047526E-01, 'flb' => 2.50369750774671E+04, 'BTU' => 1.0, 'btu' => 1.0, ) ), 'Power' => array( 'HP' => array( 'HP' => 1.0, 'h' => 1.0, 'W' => 7.45701000000000E+02, 'w' => 7.45701000000000E+02 ), 'h' => array( 'HP' => 1.0, 'h' => 1.0, 'W' => 7.45701000000000E+02, 'w' => 7.45701000000000E+02 ), 'W' => array( 'HP' => 1.34102006031908E-03, 'h' => 1.34102006031908E-03, 'W' => 1.0, 'w' => 1.0 ), 'w' => array( 'HP' => 1.34102006031908E-03, 'h' => 1.34102006031908E-03, 'W' => 1.0, 'w' => 1.0 ) ), 'Magnetism' => array( 'T' => array( 'T' => 1.0, 'ga' => 10000.0 ), 'ga' => array( 'T' => 0.0001, 'ga' => 1.0 ) ), 'Liquid' => array( 'tsp' => array( 'tsp' => 1.0, 'tbs' => 3.33333333333333E-01, 'oz' => 1.66666666666667E-01, 'cup' => 2.08333333333333E-02, 'pt' => 1.04166666666667E-02, 'us_pt' => 1.04166666666667E-02, 'uk_pt' => 8.67558516821960E-03, 'qt' => 5.20833333333333E-03, 'gal' => 1.30208333333333E-03, 'l' => 4.92999408400710E-03, 'lt' => 4.92999408400710E-03 ), 'tbs' => array( 'tsp' => 3.00000000000000E+00, 'tbs' => 1.0, 'oz' => 5.00000000000000E-01, 'cup' => 6.25000000000000E-02, 'pt' => 3.12500000000000E-02, 'us_pt' => 3.12500000000000E-02, 'uk_pt' => 2.60267555046588E-02, 'qt' => 1.56250000000000E-02, 'gal' => 3.90625000000000E-03, 'l' => 1.47899822520213E-02, 'lt' => 1.47899822520213E-02 ), 'oz' => array( 'tsp' => 6.00000000000000E+00, 'tbs' => 2.00000000000000E+00, 'oz' => 1.0, 'cup' => 1.25000000000000E-01, 'pt' => 6.25000000000000E-02, 'us_pt' => 6.25000000000000E-02, 'uk_pt' => 5.20535110093176E-02, 'qt' => 3.12500000000000E-02, 'gal' => 7.81250000000000E-03, 'l' => 2.95799645040426E-02, 'lt' => 2.95799645040426E-02 ), 'cup' => array( 'tsp' => 4.80000000000000E+01, 'tbs' => 1.60000000000000E+01, 'oz' => 8.00000000000000E+00, 'cup' => 1.0, 'pt' => 5.00000000000000E-01, 'us_pt' => 5.00000000000000E-01, 'uk_pt' => 4.16428088074541E-01, 'qt' => 2.50000000000000E-01, 'gal' => 6.25000000000000E-02, 'l' => 2.36639716032341E-01, 'lt' => 2.36639716032341E-01 ), 'pt' => array( 'tsp' => 9.60000000000000E+01, 'tbs' => 3.20000000000000E+01, 'oz' => 1.60000000000000E+01, 'cup' => 2.00000000000000E+00, 'pt' => 1.0, 'us_pt' => 1.0, 'uk_pt' => 8.32856176149081E-01, 'qt' => 5.00000000000000E-01, 'gal' => 1.25000000000000E-01, 'l' => 4.73279432064682E-01, 'lt' => 4.73279432064682E-01 ), 'us_pt' => array( 'tsp' => 9.60000000000000E+01, 'tbs' => 3.20000000000000E+01, 'oz' => 1.60000000000000E+01, 'cup' => 2.00000000000000E+00, 'pt' => 1.0, 'us_pt' => 1.0, 'uk_pt' => 8.32856176149081E-01, 'qt' => 5.00000000000000E-01, 'gal' => 1.25000000000000E-01, 'l' => 4.73279432064682E-01, 'lt' => 4.73279432064682E-01 ), 'uk_pt' => array( 'tsp' => 1.15266000000000E+02, 'tbs' => 3.84220000000000E+01, 'oz' => 1.92110000000000E+01, 'cup' => 2.40137500000000E+00, 'pt' => 1.20068750000000E+00, 'us_pt' => 1.20068750000000E+00, 'uk_pt' => 1.0, 'qt' => 6.00343750000000E-01, 'gal' => 1.50085937500000E-01, 'l' => 5.68260698087162E-01, 'lt' => 5.68260698087162E-01 ), 'qt' => array( 'tsp' => 1.92000000000000E+02, 'tbs' => 6.40000000000000E+01, 'oz' => 3.20000000000000E+01, 'cup' => 4.00000000000000E+00, 'pt' => 2.00000000000000E+00, 'us_pt' => 2.00000000000000E+00, 'uk_pt' => 1.66571235229816E+00, 'qt' => 1.0, 'gal' => 2.50000000000000E-01, 'l' => 9.46558864129363E-01, 'lt' => 9.46558864129363E-01 ), 'gal' => array( 'tsp' => 7.68000000000000E+02, 'tbs' => 2.56000000000000E+02, 'oz' => 1.28000000000000E+02, 'cup' => 1.60000000000000E+01, 'pt' => 8.00000000000000E+00, 'us_pt' => 8.00000000000000E+00, 'uk_pt' => 6.66284940919265E+00, 'qt' => 4.00000000000000E+00, 'gal' => 1.0, 'l' => 3.78623545651745E+00, 'lt' => 3.78623545651745E+00 ), 'l' => array( 'tsp' => 2.02840000000000E+02, 'tbs' => 6.76133333333333E+01, 'oz' => 3.38066666666667E+01, 'cup' => 4.22583333333333E+00, 'pt' => 2.11291666666667E+00, 'us_pt' => 2.11291666666667E+00, 'uk_pt' => 1.75975569552166E+00, 'qt' => 1.05645833333333E+00, 'gal' => 2.64114583333333E-01, 'l' => 1.0, 'lt' => 1.0 ), 'lt' => array( 'tsp' => 2.02840000000000E+02, 'tbs' => 6.76133333333333E+01, 'oz' => 3.38066666666667E+01, 'cup' => 4.22583333333333E+00, 'pt' => 2.11291666666667E+00, 'us_pt' => 2.11291666666667E+00, 'uk_pt' => 1.75975569552166E+00, 'qt' => 1.05645833333333E+00, 'gal' => 2.64114583333333E-01, 'l' => 1.0, 'lt' => 1.0 ) ) ); /** * _parseComplex * * Parses a complex number into its real and imaginary parts, and an I or J suffix * * @param string $complexNumber The complex number * @return string[] Indexed on "real", "imaginary" and "suffix" */ public static function _parseComplex($complexNumber) { $workString = (string) $complexNumber; $realNumber = $imaginary = 0; // Extract the suffix, if there is one $suffix = substr($workString,-1); if (!is_numeric($suffix)) { $workString = substr($workString,0,-1); } else { $suffix = ''; } // Split the input into its Real and Imaginary components $leadingSign = 0; if (strlen($workString) > 0) { $leadingSign = (($workString{0} == '+') || ($workString{0} == '-')) ? 1 : 0; } $power = ''; $realNumber = strtok($workString, '+-'); if (strtoupper(substr($realNumber,-1)) == 'E') { $power = strtok('+-'); ++$leadingSign; } $realNumber = substr($workString,0,strlen($realNumber)+strlen($power)+$leadingSign); if ($suffix != '') { $imaginary = substr($workString,strlen($realNumber)); if (($imaginary == '') && (($realNumber == '') || ($realNumber == '+') || ($realNumber == '-'))) { $imaginary = $realNumber.'1'; $realNumber = '0'; } else if ($imaginary == '') { $imaginary = $realNumber; $realNumber = '0'; } elseif (($imaginary == '+') || ($imaginary == '-')) { $imaginary .= '1'; } } return array( 'real' => $realNumber, 'imaginary' => $imaginary, 'suffix' => $suffix ); } // function _parseComplex() /** * Cleans the leading characters in a complex number string * * @param string $complexNumber The complex number to clean * @return string The "cleaned" complex number */ private static function _cleanComplex($complexNumber) { if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1); if ($complexNumber{0} == '0') $complexNumber = substr($complexNumber,1); if ($complexNumber{0} == '.') $complexNumber = '0'.$complexNumber; if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1); return $complexNumber; } /** * Formats a number base string value with leading zeroes * * @param string $xVal The "number" to pad * @param integer $places The length that we want to pad this value * @return string The padded "number" */ private static function _nbrConversionFormat($xVal, $places) { if (!is_null($places)) { if (strlen($xVal) <= $places) { return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10); } else { return PHPExcel_Calculation_Functions::NaN(); } } return substr($xVal, -10); } // function _nbrConversionFormat() /** * BESSELI * * Returns the modified Bessel function In(x), which is equivalent to the Bessel function evaluated * for purely imaginary arguments * * Excel Function: * BESSELI(x,ord) * * @access public * @category Engineering Functions * @param float $x The value at which to evaluate the function. * If x is nonnumeric, BESSELI returns the #VALUE! error value. * @param integer $ord The order of the Bessel function. * If ord is not an integer, it is truncated. * If $ord is nonnumeric, BESSELI returns the #VALUE! error value. * If $ord < 0, BESSELI returns the #NUM! error value. * @return float * */ public static function BESSELI($x, $ord) { $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x); $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord); if ((is_numeric($x)) && (is_numeric($ord))) { $ord = floor($ord); if ($ord < 0) { return PHPExcel_Calculation_Functions::NaN(); } if (abs($x) <= 30) { $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord); $ordK = 1; $fSqrX = ($x * $x) / 4; do { $fTerm *= $fSqrX; $fTerm /= ($ordK * ($ordK + $ord)); $fResult += $fTerm; } while ((abs($fTerm) > 1e-12) && (++$ordK < 100)); } else { $f_2_PI = 2 * M_PI; $fXAbs = abs($x); $fResult = exp($fXAbs) / sqrt($f_2_PI * $fXAbs); if (($ord & 1) && ($x < 0)) { $fResult = -$fResult; } } return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult; } return PHPExcel_Calculation_Functions::VALUE(); } // function BESSELI() /** * BESSELJ * * Returns the Bessel function * * Excel Function: * BESSELJ(x,ord) * * @access public * @category Engineering Functions * @param float $x The value at which to evaluate the function. * If x is nonnumeric, BESSELJ returns the #VALUE! error value. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated. * If $ord is nonnumeric, BESSELJ returns the #VALUE! error value. * If $ord < 0, BESSELJ returns the #NUM! error value. * @return float * */ public static function BESSELJ($x, $ord) { $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x); $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord); if ((is_numeric($x)) && (is_numeric($ord))) { $ord = floor($ord); if ($ord < 0) { return PHPExcel_Calculation_Functions::NaN(); } $fResult = 0; if (abs($x) <= 30) { $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord); $ordK = 1; $fSqrX = ($x * $x) / -4; do { $fTerm *= $fSqrX; $fTerm /= ($ordK * ($ordK + $ord)); $fResult += $fTerm; } while ((abs($fTerm) > 1e-12) && (++$ordK < 100)); } else { $f_PI_DIV_2 = M_PI / 2; $f_PI_DIV_4 = M_PI / 4; $fXAbs = abs($x); $fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4); if (($ord & 1) && ($x < 0)) { $fResult = -$fResult; } } return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult; } return PHPExcel_Calculation_Functions::VALUE(); } // function BESSELJ() private static function _Besselk0($fNum) { if ($fNum <= 2) { $fNum2 = $fNum * 0.5; $y = ($fNum2 * $fNum2); $fRet = -log($fNum2) * self::BESSELI($fNum, 0) + (-0.57721566 + $y * (0.42278420 + $y * (0.23069756 + $y * (0.3488590e-1 + $y * (0.262698e-2 + $y * (0.10750e-3 + $y * 0.74e-5)))))); } else { $y = 2 / $fNum; $fRet = exp(-$fNum) / sqrt($fNum) * (1.25331414 + $y * (-0.7832358e-1 + $y * (0.2189568e-1 + $y * (-0.1062446e-1 + $y * (0.587872e-2 + $y * (-0.251540e-2 + $y * 0.53208e-3)))))); } return $fRet; } // function _Besselk0() private static function _Besselk1($fNum) { if ($fNum <= 2) { $fNum2 = $fNum * 0.5; $y = ($fNum2 * $fNum2); $fRet = log($fNum2) * self::BESSELI($fNum, 1) + (1 + $y * (0.15443144 + $y * (-0.67278579 + $y * (-0.18156897 + $y * (-0.1919402e-1 + $y * (-0.110404e-2 + $y * (-0.4686e-4))))))) / $fNum; } else { $y = 2 / $fNum; $fRet = exp(-$fNum) / sqrt($fNum) * (1.25331414 + $y * (0.23498619 + $y * (-0.3655620e-1 + $y * (0.1504268e-1 + $y * (-0.780353e-2 + $y * (0.325614e-2 + $y * (-0.68245e-3))))))); } return $fRet; } // function _Besselk1() /** * BESSELK * * Returns the modified Bessel function Kn(x), which is equivalent to the Bessel functions evaluated * for purely imaginary arguments. * * Excel Function: * BESSELK(x,ord) * * @access public * @category Engineering Functions * @param float $x The value at which to evaluate the function. * If x is nonnumeric, BESSELK returns the #VALUE! error value. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value. * If $ord < 0, BESSELK returns the #NUM! error value. * @return float * */ public static function BESSELK($x, $ord) { $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x); $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord); if ((is_numeric($x)) && (is_numeric($ord))) { if (($ord < 0) || ($x == 0.0)) { return PHPExcel_Calculation_Functions::NaN(); } switch(floor($ord)) { case 0 : return self::_Besselk0($x); break; case 1 : return self::_Besselk1($x); break; default : $fTox = 2 / $x; $fBkm = self::_Besselk0($x); $fBk = self::_Besselk1($x); for ($n = 1; $n < $ord; ++$n) { $fBkp = $fBkm + $n * $fTox * $fBk; $fBkm = $fBk; $fBk = $fBkp; } } return (is_nan($fBk)) ? PHPExcel_Calculation_Functions::NaN() : $fBk; } return PHPExcel_Calculation_Functions::VALUE(); } // function BESSELK() private static function _Bessely0($fNum) { if ($fNum < 8.0) { $y = ($fNum * $fNum); $f1 = -2957821389.0 + $y * (7062834065.0 + $y * (-512359803.6 + $y * (10879881.29 + $y * (-86327.92757 + $y * 228.4622733)))); $f2 = 40076544269.0 + $y * (745249964.8 + $y * (7189466.438 + $y * (47447.26470 + $y * (226.1030244 + $y)))); $fRet = $f1 / $f2 + 0.636619772 * self::BESSELJ($fNum, 0) * log($fNum); } else { $z = 8.0 / $fNum; $y = ($z * $z); $xx = $fNum - 0.785398164; $f1 = 1 + $y * (-0.1098628627e-2 + $y * (0.2734510407e-4 + $y * (-0.2073370639e-5 + $y * 0.2093887211e-6))); $f2 = -0.1562499995e-1 + $y * (0.1430488765e-3 + $y * (-0.6911147651e-5 + $y * (0.7621095161e-6 + $y * (-0.934945152e-7)))); $fRet = sqrt(0.636619772 / $fNum) * (sin($xx) * $f1 + $z * cos($xx) * $f2); } return $fRet; } // function _Bessely0() private static function _Bessely1($fNum) { if ($fNum < 8.0) { $y = ($fNum * $fNum); $f1 = $fNum * (-0.4900604943e13 + $y * (0.1275274390e13 + $y * (-0.5153438139e11 + $y * (0.7349264551e9 + $y * (-0.4237922726e7 + $y * 0.8511937935e4))))); $f2 = 0.2499580570e14 + $y * (0.4244419664e12 + $y * (0.3733650367e10 + $y * (0.2245904002e8 + $y * (0.1020426050e6 + $y * (0.3549632885e3 + $y))))); $fRet = $f1 / $f2 + 0.636619772 * ( self::BESSELJ($fNum, 1) * log($fNum) - 1 / $fNum); } else { $fRet = sqrt(0.636619772 / $fNum) * sin($fNum - 2.356194491); } return $fRet; } // function _Bessely1() /** * BESSELY * * Returns the Bessel function, which is also called the Weber function or the Neumann function. * * Excel Function: * BESSELY(x,ord) * * @access public * @category Engineering Functions * @param float $x The value at which to evaluate the function. * If x is nonnumeric, BESSELK returns the #VALUE! error value. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value. * If $ord < 0, BESSELK returns the #NUM! error value. * * @return float */ public static function BESSELY($x, $ord) { $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x); $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord); if ((is_numeric($x)) && (is_numeric($ord))) { if (($ord < 0) || ($x == 0.0)) { return PHPExcel_Calculation_Functions::NaN(); } switch(floor($ord)) { case 0 : return self::_Bessely0($x); break; case 1 : return self::_Bessely1($x); break; default: $fTox = 2 / $x; $fBym = self::_Bessely0($x); $fBy = self::_Bessely1($x); for ($n = 1; $n < $ord; ++$n) { $fByp = $n * $fTox * $fBy - $fBym; $fBym = $fBy; $fBy = $fByp; } } return (is_nan($fBy)) ? PHPExcel_Calculation_Functions::NaN() : $fBy; } return PHPExcel_Calculation_Functions::VALUE(); } // function BESSELY() /** * BINTODEC * * Return a binary value as decimal. * * Excel Function: * BIN2DEC(x) * * @access public * @category Engineering Functions * @param string $x The binary number (as a string) that you want to convert. The number * cannot contain more than 10 characters (10 bits). The most significant * bit of number is the sign bit. The remaining 9 bits are magnitude bits. * Negative numbers are represented using two's-complement notation. * If number is not a valid binary number, or if number contains more than * 10 characters (10 bits), BIN2DEC returns the #NUM! error value. * @return string */ public static function BINTODEC($x) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); if (is_bool($x)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { $x = (int) $x; } else { return PHPExcel_Calculation_Functions::VALUE(); } } if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { $x = floor($x); } $x = (string) $x; if (strlen($x) > preg_match_all('/[01]/',$x,$out)) { return PHPExcel_Calculation_Functions::NaN(); } if (strlen($x) > 10) { return PHPExcel_Calculation_Functions::NaN(); } elseif (strlen($x) == 10) { // Two's Complement $x = substr($x,-9); return '-'.(512-bindec($x)); } return bindec($x); } // function BINTODEC() /** * BINTOHEX * * Return a binary value as hex. * * Excel Function: * BIN2HEX(x[,places]) * * @access public * @category Engineering Functions * @param string $x The binary number (as a string) that you want to convert. The number * cannot contain more than 10 characters (10 bits). The most significant * bit of number is the sign bit. The remaining 9 bits are magnitude bits. * Negative numbers are represented using two's-complement notation. * If number is not a valid binary number, or if number contains more than * 10 characters (10 bits), BIN2HEX returns the #NUM! error value. * @param integer $places The number of characters to use. If places is omitted, BIN2HEX uses the * minimum number of characters necessary. Places is useful for padding the * return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, BIN2HEX returns the #VALUE! error value. * If places is negative, BIN2HEX returns the #NUM! error value. * @return string */ public static function BINTOHEX($x, $places=NULL) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); if (is_bool($x)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { $x = (int) $x; } else { return PHPExcel_Calculation_Functions::VALUE(); } } if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { $x = floor($x); } $x = (string) $x; if (strlen($x) > preg_match_all('/[01]/',$x,$out)) { return PHPExcel_Calculation_Functions::NaN(); } if (strlen($x) > 10) { return PHPExcel_Calculation_Functions::NaN(); } elseif (strlen($x) == 10) { // Two's Complement return str_repeat('F',8).substr(strtoupper(dechex(bindec(substr($x,-9)))),-2); } $hexVal = (string) strtoupper(dechex(bindec($x))); return self::_nbrConversionFormat($hexVal,$places); } // function BINTOHEX() /** * BINTOOCT * * Return a binary value as octal. * * Excel Function: * BIN2OCT(x[,places]) * * @access public * @category Engineering Functions * @param string $x The binary number (as a string) that you want to convert. The number * cannot contain more than 10 characters (10 bits). The most significant * bit of number is the sign bit. The remaining 9 bits are magnitude bits. * Negative numbers are represented using two's-complement notation. * If number is not a valid binary number, or if number contains more than * 10 characters (10 bits), BIN2OCT returns the #NUM! error value. * @param integer $places The number of characters to use. If places is omitted, BIN2OCT uses the * minimum number of characters necessary. Places is useful for padding the * return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, BIN2OCT returns the #VALUE! error value. * If places is negative, BIN2OCT returns the #NUM! error value. * @return string */ public static function BINTOOCT($x, $places=NULL) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); if (is_bool($x)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { $x = (int) $x; } else { return PHPExcel_Calculation_Functions::VALUE(); } } if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { $x = floor($x); } $x = (string) $x; if (strlen($x) > preg_match_all('/[01]/',$x,$out)) { return PHPExcel_Calculation_Functions::NaN(); } if (strlen($x) > 10) { return PHPExcel_Calculation_Functions::NaN(); } elseif (strlen($x) == 10) { // Two's Complement return str_repeat('7',7).substr(strtoupper(decoct(bindec(substr($x,-9)))),-3); } $octVal = (string) decoct(bindec($x)); return self::_nbrConversionFormat($octVal,$places); } // function BINTOOCT() /** * DECTOBIN * * Return a decimal value as binary. * * Excel Function: * DEC2BIN(x[,places]) * * @access public * @category Engineering Functions * @param string $x The decimal integer you want to convert. If number is negative, * valid place values are ignored and DEC2BIN returns a 10-character * (10-bit) binary number in which the most significant bit is the sign * bit. The remaining 9 bits are magnitude bits. Negative numbers are * represented using two's-complement notation. * If number < -512 or if number > 511, DEC2BIN returns the #NUM! error * value. * If number is nonnumeric, DEC2BIN returns the #VALUE! error value. * If DEC2BIN requires more than places characters, it returns the #NUM! * error value. * @param integer $places The number of characters to use. If places is omitted, DEC2BIN uses * the minimum number of characters necessary. Places is useful for * padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, DEC2BIN returns the #VALUE! error value. * If places is zero or negative, DEC2BIN returns the #NUM! error value. * @return string */ public static function DECTOBIN($x, $places=NULL) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); if (is_bool($x)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { $x = (int) $x; } else { return PHPExcel_Calculation_Functions::VALUE(); } } $x = (string) $x; if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) { return PHPExcel_Calculation_Functions::VALUE(); } $x = (string) floor($x); $r = decbin($x); if (strlen($r) == 32) { // Two's Complement $r = substr($r,-10); } elseif (strlen($r) > 11) { return PHPExcel_Calculation_Functions::NaN(); } return self::_nbrConversionFormat($r,$places); } // function DECTOBIN() /** * DECTOHEX * * Return a decimal value as hex. * * Excel Function: * DEC2HEX(x[,places]) * * @access public * @category Engineering Functions * @param string $x The decimal integer you want to convert. If number is negative, * places is ignored and DEC2HEX returns a 10-character (40-bit) * hexadecimal number in which the most significant bit is the sign * bit. The remaining 39 bits are magnitude bits. Negative numbers * are represented using two's-complement notation. * If number < -549,755,813,888 or if number > 549,755,813,887, * DEC2HEX returns the #NUM! error value. * If number is nonnumeric, DEC2HEX returns the #VALUE! error value. * If DEC2HEX requires more than places characters, it returns the * #NUM! error value. * @param integer $places The number of characters to use. If places is omitted, DEC2HEX uses * the minimum number of characters necessary. Places is useful for * padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, DEC2HEX returns the #VALUE! error value. * If places is zero or negative, DEC2HEX returns the #NUM! error value. * @return string */ public static function DECTOHEX($x, $places=null) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); if (is_bool($x)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { $x = (int) $x; } else { return PHPExcel_Calculation_Functions::VALUE(); } } $x = (string) $x; if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) { return PHPExcel_Calculation_Functions::VALUE(); } $x = (string) floor($x); $r = strtoupper(dechex($x)); if (strlen($r) == 8) { // Two's Complement $r = 'FF'.$r; } return self::_nbrConversionFormat($r,$places); } // function DECTOHEX() /** * DECTOOCT * * Return an decimal value as octal. * * Excel Function: * DEC2OCT(x[,places]) * * @access public * @category Engineering Functions * @param string $x The decimal integer you want to convert. If number is negative, * places is ignored and DEC2OCT returns a 10-character (30-bit) * octal number in which the most significant bit is the sign bit. * The remaining 29 bits are magnitude bits. Negative numbers are * represented using two's-complement notation. * If number < -536,870,912 or if number > 536,870,911, DEC2OCT * returns the #NUM! error value. * If number is nonnumeric, DEC2OCT returns the #VALUE! error value. * If DEC2OCT requires more than places characters, it returns the * #NUM! error value. * @param integer $places The number of characters to use. If places is omitted, DEC2OCT uses * the minimum number of characters necessary. Places is useful for * padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, DEC2OCT returns the #VALUE! error value. * If places is zero or negative, DEC2OCT returns the #NUM! error value. * @return string */ public static function DECTOOCT($x, $places=null) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); if (is_bool($x)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { $x = (int) $x; } else { return PHPExcel_Calculation_Functions::VALUE(); } } $x = (string) $x; if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) { return PHPExcel_Calculation_Functions::VALUE(); } $x = (string) floor($x); $r = decoct($x); if (strlen($r) == 11) { // Two's Complement $r = substr($r,-10); } return self::_nbrConversionFormat($r,$places); } // function DECTOOCT() /** * HEXTOBIN * * Return a hex value as binary. * * Excel Function: * HEX2BIN(x[,places]) * * @access public * @category Engineering Functions * @param string $x the hexadecimal number you want to convert. Number cannot * contain more than 10 characters. The most significant bit of * number is the sign bit (40th bit from the right). The remaining * 9 bits are magnitude bits. Negative numbers are represented * using two's-complement notation. * If number is negative, HEX2BIN ignores places and returns a * 10-character binary number. * If number is negative, it cannot be less than FFFFFFFE00, and * if number is positive, it cannot be greater than 1FF. * If number is not a valid hexadecimal number, HEX2BIN returns * the #NUM! error value. * If HEX2BIN requires more than places characters, it returns * the #NUM! error value. * @param integer $places The number of characters to use. If places is omitted, * HEX2BIN uses the minimum number of characters necessary. Places * is useful for padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, HEX2BIN returns the #VALUE! error value. * If places is negative, HEX2BIN returns the #NUM! error value. * @return string */ public static function HEXTOBIN($x, $places=null) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); if (is_bool($x)) { return PHPExcel_Calculation_Functions::VALUE(); } $x = (string) $x; if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) { return PHPExcel_Calculation_Functions::NaN(); } $binVal = decbin(hexdec($x)); return substr(self::_nbrConversionFormat($binVal,$places),-10); } // function HEXTOBIN() /** * HEXTODEC * * Return a hex value as decimal. * * Excel Function: * HEX2DEC(x) * * @access public * @category Engineering Functions * @param string $x The hexadecimal number you want to convert. This number cannot * contain more than 10 characters (40 bits). The most significant * bit of number is the sign bit. The remaining 39 bits are magnitude * bits. Negative numbers are represented using two's-complement * notation. * If number is not a valid hexadecimal number, HEX2DEC returns the * #NUM! error value. * @return string */ public static function HEXTODEC($x) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); if (is_bool($x)) { return PHPExcel_Calculation_Functions::VALUE(); } $x = (string) $x; if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) { return PHPExcel_Calculation_Functions::NaN(); } return hexdec($x); } // function HEXTODEC() /** * HEXTOOCT * * Return a hex value as octal. * * Excel Function: * HEX2OCT(x[,places]) * * @access public * @category Engineering Functions * @param string $x The hexadecimal number you want to convert. Number cannot * contain more than 10 characters. The most significant bit of * number is the sign bit. The remaining 39 bits are magnitude * bits. Negative numbers are represented using two's-complement * notation. * If number is negative, HEX2OCT ignores places and returns a * 10-character octal number. * If number is negative, it cannot be less than FFE0000000, and * if number is positive, it cannot be greater than 1FFFFFFF. * If number is not a valid hexadecimal number, HEX2OCT returns * the #NUM! error value. * If HEX2OCT requires more than places characters, it returns * the #NUM! error value. * @param integer $places The number of characters to use. If places is omitted, HEX2OCT * uses the minimum number of characters necessary. Places is * useful for padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, HEX2OCT returns the #VALUE! error * value. * If places is negative, HEX2OCT returns the #NUM! error value. * @return string */ public static function HEXTOOCT($x, $places=null) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); if (is_bool($x)) { return PHPExcel_Calculation_Functions::VALUE(); } $x = (string) $x; if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) { return PHPExcel_Calculation_Functions::NaN(); } $octVal = decoct(hexdec($x)); return self::_nbrConversionFormat($octVal,$places); } // function HEXTOOCT() /** * OCTTOBIN * * Return an octal value as binary. * * Excel Function: * OCT2BIN(x[,places]) * * @access public * @category Engineering Functions * @param string $x The octal number you want to convert. Number may not * contain more than 10 characters. The most significant * bit of number is the sign bit. The remaining 29 bits * are magnitude bits. Negative numbers are represented * using two's-complement notation. * If number is negative, OCT2BIN ignores places and returns * a 10-character binary number. * If number is negative, it cannot be less than 7777777000, * and if number is positive, it cannot be greater than 777. * If number is not a valid octal number, OCT2BIN returns * the #NUM! error value. * If OCT2BIN requires more than places characters, it * returns the #NUM! error value. * @param integer $places The number of characters to use. If places is omitted, * OCT2BIN uses the minimum number of characters necessary. * Places is useful for padding the return value with * leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, OCT2BIN returns the #VALUE! * error value. * If places is negative, OCT2BIN returns the #NUM! error * value. * @return string */ public static function OCTTOBIN($x, $places=null) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); if (is_bool($x)) { return PHPExcel_Calculation_Functions::VALUE(); } $x = (string) $x; if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) { return PHPExcel_Calculation_Functions::NaN(); } $r = decbin(octdec($x)); return self::_nbrConversionFormat($r,$places); } // function OCTTOBIN() /** * OCTTODEC * * Return an octal value as decimal. * * Excel Function: * OCT2DEC(x) * * @access public * @category Engineering Functions * @param string $x The octal number you want to convert. Number may not contain * more than 10 octal characters (30 bits). The most significant * bit of number is the sign bit. The remaining 29 bits are * magnitude bits. Negative numbers are represented using * two's-complement notation. * If number is not a valid octal number, OCT2DEC returns the * #NUM! error value. * @return string */ public static function OCTTODEC($x) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); if (is_bool($x)) { return PHPExcel_Calculation_Functions::VALUE(); } $x = (string) $x; if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) { return PHPExcel_Calculation_Functions::NaN(); } return octdec($x); } // function OCTTODEC() /** * OCTTOHEX * * Return an octal value as hex. * * Excel Function: * OCT2HEX(x[,places]) * * @access public * @category Engineering Functions * @param string $x The octal number you want to convert. Number may not contain * more than 10 octal characters (30 bits). The most significant * bit of number is the sign bit. The remaining 29 bits are * magnitude bits. Negative numbers are represented using * two's-complement notation. * If number is negative, OCT2HEX ignores places and returns a * 10-character hexadecimal number. * If number is not a valid octal number, OCT2HEX returns the * #NUM! error value. * If OCT2HEX requires more than places characters, it returns * the #NUM! error value. * @param integer $places The number of characters to use. If places is omitted, OCT2HEX * uses the minimum number of characters necessary. Places is useful * for padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, OCT2HEX returns the #VALUE! error value. * If places is negative, OCT2HEX returns the #NUM! error value. * @return string */ public static function OCTTOHEX($x, $places=null) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); if (is_bool($x)) { return PHPExcel_Calculation_Functions::VALUE(); } $x = (string) $x; if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) { return PHPExcel_Calculation_Functions::NaN(); } $hexVal = strtoupper(dechex(octdec($x))); return self::_nbrConversionFormat($hexVal,$places); } // function OCTTOHEX() /** * COMPLEX * * Converts real and imaginary coefficients into a complex number of the form x + yi or x + yj. * * Excel Function: * COMPLEX(realNumber,imaginary[,places]) * * @access public * @category Engineering Functions * @param float $realNumber The real coefficient of the complex number. * @param float $imaginary The imaginary coefficient of the complex number. * @param string $suffix The suffix for the imaginary component of the complex number. * If omitted, the suffix is assumed to be "i". * @return string */ public static function COMPLEX($realNumber=0.0, $imaginary=0.0, $suffix='i') { $realNumber = (is_null($realNumber)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($realNumber); $imaginary = (is_null($imaginary)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($imaginary); $suffix = (is_null($suffix)) ? 'i' : PHPExcel_Calculation_Functions::flattenSingleValue($suffix); if (((is_numeric($realNumber)) && (is_numeric($imaginary))) && (($suffix == 'i') || ($suffix == 'j') || ($suffix == ''))) { $realNumber = (float) $realNumber; $imaginary = (float) $imaginary; if ($suffix == '') $suffix = 'i'; if ($realNumber == 0.0) { if ($imaginary == 0.0) { return (string) '0'; } elseif ($imaginary == 1.0) { return (string) $suffix; } elseif ($imaginary == -1.0) { return (string) '-'.$suffix; } return (string) $imaginary.$suffix; } elseif ($imaginary == 0.0) { return (string) $realNumber; } elseif ($imaginary == 1.0) { return (string) $realNumber.'+'.$suffix; } elseif ($imaginary == -1.0) { return (string) $realNumber.'-'.$suffix; } if ($imaginary > 0) { $imaginary = (string) '+'.$imaginary; } return (string) $realNumber.$imaginary.$suffix; } return PHPExcel_Calculation_Functions::VALUE(); } // function COMPLEX() /** * IMAGINARY * * Returns the imaginary coefficient of a complex number in x + yi or x + yj text format. * * Excel Function: * IMAGINARY(complexNumber) * * @access public * @category Engineering Functions * @param string $complexNumber The complex number for which you want the imaginary * coefficient. * @return float */ public static function IMAGINARY($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); return $parsedComplex['imaginary']; } // function IMAGINARY() /** * IMREAL * * Returns the real coefficient of a complex number in x + yi or x + yj text format. * * Excel Function: * IMREAL(complexNumber) * * @access public * @category Engineering Functions * @param string $complexNumber The complex number for which you want the real coefficient. * @return float */ public static function IMREAL($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); return $parsedComplex['real']; } // function IMREAL() /** * IMABS * * Returns the absolute value (modulus) of a complex number in x + yi or x + yj text format. * * Excel Function: * IMABS(complexNumber) * * @param string $complexNumber The complex number for which you want the absolute value. * @return float */ public static function IMABS($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); return sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])); } // function IMABS() /** * IMARGUMENT * * Returns the argument theta of a complex number, i.e. the angle in radians from the real * axis to the representation of the number in polar coordinates. * * Excel Function: * IMARGUMENT(complexNumber) * * @param string $complexNumber The complex number for which you want the argument theta. * @return float */ public static function IMARGUMENT($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); if ($parsedComplex['real'] == 0.0) { if ($parsedComplex['imaginary'] == 0.0) { return 0.0; } elseif($parsedComplex['imaginary'] < 0.0) { return M_PI / -2; } else { return M_PI / 2; } } elseif ($parsedComplex['real'] > 0.0) { return atan($parsedComplex['imaginary'] / $parsedComplex['real']); } elseif ($parsedComplex['imaginary'] < 0.0) { return 0 - (M_PI - atan(abs($parsedComplex['imaginary']) / abs($parsedComplex['real']))); } else { return M_PI - atan($parsedComplex['imaginary'] / abs($parsedComplex['real'])); } } // function IMARGUMENT() /** * IMCONJUGATE * * Returns the complex conjugate of a complex number in x + yi or x + yj text format. * * Excel Function: * IMCONJUGATE(complexNumber) * * @param string $complexNumber The complex number for which you want the conjugate. * @return string */ public static function IMCONJUGATE($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); if ($parsedComplex['imaginary'] == 0.0) { return $parsedComplex['real']; } else { return self::_cleanComplex( self::COMPLEX( $parsedComplex['real'], 0 - $parsedComplex['imaginary'], $parsedComplex['suffix'] ) ); } } // function IMCONJUGATE() /** * IMCOS * * Returns the cosine of a complex number in x + yi or x + yj text format. * * Excel Function: * IMCOS(complexNumber) * * @param string $complexNumber The complex number for which you want the cosine. * @return string|float */ public static function IMCOS($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); if ($parsedComplex['imaginary'] == 0.0) { return cos($parsedComplex['real']); } else { return self::IMCONJUGATE(self::COMPLEX(cos($parsedComplex['real']) * cosh($parsedComplex['imaginary']),sin($parsedComplex['real']) * sinh($parsedComplex['imaginary']),$parsedComplex['suffix'])); } } // function IMCOS() /** * IMSIN * * Returns the sine of a complex number in x + yi or x + yj text format. * * Excel Function: * IMSIN(complexNumber) * * @param string $complexNumber The complex number for which you want the sine. * @return string|float */ public static function IMSIN($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); if ($parsedComplex['imaginary'] == 0.0) { return sin($parsedComplex['real']); } else { return self::COMPLEX(sin($parsedComplex['real']) * cosh($parsedComplex['imaginary']),cos($parsedComplex['real']) * sinh($parsedComplex['imaginary']),$parsedComplex['suffix']); } } // function IMSIN() /** * IMSQRT * * Returns the square root of a complex number in x + yi or x + yj text format. * * Excel Function: * IMSQRT(complexNumber) * * @param string $complexNumber The complex number for which you want the square root. * @return string */ public static function IMSQRT($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); $theta = self::IMARGUMENT($complexNumber); $d1 = cos($theta / 2); $d2 = sin($theta / 2); $r = sqrt(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']))); if ($parsedComplex['suffix'] == '') { return self::COMPLEX($d1 * $r,$d2 * $r); } else { return self::COMPLEX($d1 * $r,$d2 * $r,$parsedComplex['suffix']); } } // function IMSQRT() /** * IMLN * * Returns the natural logarithm of a complex number in x + yi or x + yj text format. * * Excel Function: * IMLN(complexNumber) * * @param string $complexNumber The complex number for which you want the natural logarithm. * @return string */ public static function IMLN($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return PHPExcel_Calculation_Functions::NaN(); } $logR = log(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']))); $t = self::IMARGUMENT($complexNumber); if ($parsedComplex['suffix'] == '') { return self::COMPLEX($logR,$t); } else { return self::COMPLEX($logR,$t,$parsedComplex['suffix']); } } // function IMLN() /** * IMLOG10 * * Returns the common logarithm (base 10) of a complex number in x + yi or x + yj text format. * * Excel Function: * IMLOG10(complexNumber) * * @param string $complexNumber The complex number for which you want the common logarithm. * @return string */ public static function IMLOG10($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return PHPExcel_Calculation_Functions::NaN(); } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return log10($parsedComplex['real']); } return self::IMPRODUCT(log10(EULER),self::IMLN($complexNumber)); } // function IMLOG10() /** * IMLOG2 * * Returns the base-2 logarithm of a complex number in x + yi or x + yj text format. * * Excel Function: * IMLOG2(complexNumber) * * @param string $complexNumber The complex number for which you want the base-2 logarithm. * @return string */ public static function IMLOG2($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return PHPExcel_Calculation_Functions::NaN(); } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return log($parsedComplex['real'],2); } return self::IMPRODUCT(log(EULER,2),self::IMLN($complexNumber)); } // function IMLOG2() /** * IMEXP * * Returns the exponential of a complex number in x + yi or x + yj text format. * * Excel Function: * IMEXP(complexNumber) * * @param string $complexNumber The complex number for which you want the exponential. * @return string */ public static function IMEXP($complexNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $parsedComplex = self::_parseComplex($complexNumber); if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return '1'; } $e = exp($parsedComplex['real']); $eX = $e * cos($parsedComplex['imaginary']); $eY = $e * sin($parsedComplex['imaginary']); if ($parsedComplex['suffix'] == '') { return self::COMPLEX($eX,$eY); } else { return self::COMPLEX($eX,$eY,$parsedComplex['suffix']); } } // function IMEXP() /** * IMPOWER * * Returns a complex number in x + yi or x + yj text format raised to a power. * * Excel Function: * IMPOWER(complexNumber,realNumber) * * @param string $complexNumber The complex number you want to raise to a power. * @param float $realNumber The power to which you want to raise the complex number. * @return string */ public static function IMPOWER($complexNumber,$realNumber) { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $realNumber = PHPExcel_Calculation_Functions::flattenSingleValue($realNumber); if (!is_numeric($realNumber)) { return PHPExcel_Calculation_Functions::VALUE(); } $parsedComplex = self::_parseComplex($complexNumber); $r = sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])); $rPower = pow($r,$realNumber); $theta = self::IMARGUMENT($complexNumber) * $realNumber; if ($theta == 0) { return 1; } elseif ($parsedComplex['imaginary'] == 0.0) { return self::COMPLEX($rPower * cos($theta),$rPower * sin($theta),$parsedComplex['suffix']); } else { return self::COMPLEX($rPower * cos($theta),$rPower * sin($theta),$parsedComplex['suffix']); } } // function IMPOWER() /** * IMDIV * * Returns the quotient of two complex numbers in x + yi or x + yj text format. * * Excel Function: * IMDIV(complexDividend,complexDivisor) * * @param string $complexDividend The complex numerator or dividend. * @param string $complexDivisor The complex denominator or divisor. * @return string */ public static function IMDIV($complexDividend,$complexDivisor) { $complexDividend = PHPExcel_Calculation_Functions::flattenSingleValue($complexDividend); $complexDivisor = PHPExcel_Calculation_Functions::flattenSingleValue($complexDivisor); $parsedComplexDividend = self::_parseComplex($complexDividend); $parsedComplexDivisor = self::_parseComplex($complexDivisor); if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') && ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) { return PHPExcel_Calculation_Functions::NaN(); } if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] == '')) { $parsedComplexDivisor['suffix'] = $parsedComplexDividend['suffix']; } $d1 = ($parsedComplexDividend['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['imaginary']); $d2 = ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['real']) - ($parsedComplexDividend['real'] * $parsedComplexDivisor['imaginary']); $d3 = ($parsedComplexDivisor['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDivisor['imaginary'] * $parsedComplexDivisor['imaginary']); $r = $d1/$d3; $i = $d2/$d3; if ($i > 0.0) { return self::_cleanComplex($r.'+'.$i.$parsedComplexDivisor['suffix']); } elseif ($i < 0.0) { return self::_cleanComplex($r.$i.$parsedComplexDivisor['suffix']); } else { return $r; } } // function IMDIV() /** * IMSUB * * Returns the difference of two complex numbers in x + yi or x + yj text format. * * Excel Function: * IMSUB(complexNumber1,complexNumber2) * * @param string $complexNumber1 The complex number from which to subtract complexNumber2. * @param string $complexNumber2 The complex number to subtract from complexNumber1. * @return string */ public static function IMSUB($complexNumber1,$complexNumber2) { $complexNumber1 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber1); $complexNumber2 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber2); $parsedComplex1 = self::_parseComplex($complexNumber1); $parsedComplex2 = self::_parseComplex($complexNumber2); if ((($parsedComplex1['suffix'] != '') && ($parsedComplex2['suffix'] != '')) && ($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) { return PHPExcel_Calculation_Functions::NaN(); } elseif (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) { $parsedComplex1['suffix'] = $parsedComplex2['suffix']; } $d1 = $parsedComplex1['real'] - $parsedComplex2['real']; $d2 = $parsedComplex1['imaginary'] - $parsedComplex2['imaginary']; return self::COMPLEX($d1,$d2,$parsedComplex1['suffix']); } // function IMSUB() /** * IMSUM * * Returns the sum of two or more complex numbers in x + yi or x + yj text format. * * Excel Function: * IMSUM(complexNumber[,complexNumber[,...]]) * * @param string $complexNumber,... Series of complex numbers to add * @return string */ public static function IMSUM() { // Return value $returnValue = self::_parseComplex('0'); $activeSuffix = ''; // Loop through the arguments $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); foreach ($aArgs as $arg) { $parsedComplex = self::_parseComplex($arg); if ($activeSuffix == '') { $activeSuffix = $parsedComplex['suffix']; } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) { return PHPExcel_Calculation_Functions::VALUE(); } $returnValue['real'] += $parsedComplex['real']; $returnValue['imaginary'] += $parsedComplex['imaginary']; } if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; } return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix); } // function IMSUM() /** * IMPRODUCT * * Returns the product of two or more complex numbers in x + yi or x + yj text format. * * Excel Function: * IMPRODUCT(complexNumber[,complexNumber[,...]]) * * @param string $complexNumber,... Series of complex numbers to multiply * @return string */ public static function IMPRODUCT() { // Return value $returnValue = self::_parseComplex('1'); $activeSuffix = ''; // Loop through the arguments $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); foreach ($aArgs as $arg) { $parsedComplex = self::_parseComplex($arg); $workValue = $returnValue; if (($parsedComplex['suffix'] != '') && ($activeSuffix == '')) { $activeSuffix = $parsedComplex['suffix']; } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) { return PHPExcel_Calculation_Functions::NaN(); } $returnValue['real'] = ($workValue['real'] * $parsedComplex['real']) - ($workValue['imaginary'] * $parsedComplex['imaginary']); $returnValue['imaginary'] = ($workValue['real'] * $parsedComplex['imaginary']) + ($workValue['imaginary'] * $parsedComplex['real']); } if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; } return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix); } // function IMPRODUCT() /** * DELTA * * Tests whether two values are equal. Returns 1 if number1 = number2; returns 0 otherwise. * Use this function to filter a set of values. For example, by summing several DELTA * functions you calculate the count of equal pairs. This function is also known as the * Kronecker Delta function. * * Excel Function: * DELTA(a[,b]) * * @param float $a The first number. * @param float $b The second number. If omitted, b is assumed to be zero. * @return int */ public static function DELTA($a, $b=0) { $a = PHPExcel_Calculation_Functions::flattenSingleValue($a); $b = PHPExcel_Calculation_Functions::flattenSingleValue($b); return (int) ($a == $b); } // function DELTA() /** * GESTEP * * Excel Function: * GESTEP(number[,step]) * * Returns 1 if number >= step; returns 0 (zero) otherwise * Use this function to filter a set of values. For example, by summing several GESTEP * functions you calculate the count of values that exceed a threshold. * * @param float $number The value to test against step. * @param float $step The threshold value. * If you omit a value for step, GESTEP uses zero. * @return int */ public static function GESTEP($number, $step=0) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $step = PHPExcel_Calculation_Functions::flattenSingleValue($step); return (int) ($number >= $step); } // function GESTEP() // // Private method to calculate the erf value // private static $_two_sqrtpi = 1.128379167095512574; public static function _erfVal($x) { if (abs($x) > 2.2) { return 1 - self::_erfcVal($x); } $sum = $term = $x; $xsqr = ($x * $x); $j = 1; do { $term *= $xsqr / $j; $sum -= $term / (2 * $j + 1); ++$j; $term *= $xsqr / $j; $sum += $term / (2 * $j + 1); ++$j; if ($sum == 0.0) { break; } } while (abs($term / $sum) > PRECISION); return self::$_two_sqrtpi * $sum; } // function _erfVal() /** * ERF * * Returns the error function integrated between the lower and upper bound arguments. * * Note: In Excel 2007 or earlier, if you input a negative value for the upper or lower bound arguments, * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was * improved, so that it can now calculate the function for both positive and negative ranges. * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments. * * Excel Function: * ERF(lower[,upper]) * * @param float $lower lower bound for integrating ERF * @param float $upper upper bound for integrating ERF. * If omitted, ERF integrates between zero and lower_limit * @return float */ public static function ERF($lower, $upper = NULL) { $lower = PHPExcel_Calculation_Functions::flattenSingleValue($lower); $upper = PHPExcel_Calculation_Functions::flattenSingleValue($upper); if (is_numeric($lower)) { if (is_null($upper)) { return self::_erfVal($lower); } if (is_numeric($upper)) { return self::_erfVal($upper) - self::_erfVal($lower); } } return PHPExcel_Calculation_Functions::VALUE(); } // function ERF() // // Private method to calculate the erfc value // private static $_one_sqrtpi = 0.564189583547756287; private static function _erfcVal($x) { if (abs($x) < 2.2) { return 1 - self::_erfVal($x); } if ($x < 0) { return 2 - self::ERFC(-$x); } $a = $n = 1; $b = $c = $x; $d = ($x * $x) + 0.5; $q1 = $q2 = $b / $d; $t = 0; do { $t = $a * $n + $b * $x; $a = $b; $b = $t; $t = $c * $n + $d * $x; $c = $d; $d = $t; $n += 0.5; $q1 = $q2; $q2 = $b / $d; } while ((abs($q1 - $q2) / $q2) > PRECISION); return self::$_one_sqrtpi * exp(-$x * $x) * $q2; } // function _erfcVal() /** * ERFC * * Returns the complementary ERF function integrated between x and infinity * * Note: In Excel 2007 or earlier, if you input a negative value for the lower bound argument, * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was * improved, so that it can now calculate the function for both positive and negative x values. * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments. * * Excel Function: * ERFC(x) * * @param float $x The lower bound for integrating ERFC * @return float */ public static function ERFC($x) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); if (is_numeric($x)) { return self::_erfcVal($x); } return PHPExcel_Calculation_Functions::VALUE(); } // function ERFC() /** * getConversionGroups * Returns a list of the different conversion groups for UOM conversions * * @return array */ public static function getConversionGroups() { $conversionGroups = array(); foreach(self::$_conversionUnits as $conversionUnit) { $conversionGroups[] = $conversionUnit['Group']; } return array_merge(array_unique($conversionGroups)); } // function getConversionGroups() /** * getConversionGroupUnits * Returns an array of units of measure, for a specified conversion group, or for all groups * * @param string $group The group whose units of measure you want to retrieve * @return array */ public static function getConversionGroupUnits($group = NULL) { $conversionGroups = array(); foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) { if ((is_null($group)) || ($conversionGroup['Group'] == $group)) { $conversionGroups[$conversionGroup['Group']][] = $conversionUnit; } } return $conversionGroups; } // function getConversionGroupUnits() /** * getConversionGroupUnitDetails * * @param string $group The group whose units of measure you want to retrieve * @return array */ public static function getConversionGroupUnitDetails($group = NULL) { $conversionGroups = array(); foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) { if ((is_null($group)) || ($conversionGroup['Group'] == $group)) { $conversionGroups[$conversionGroup['Group']][] = array( 'unit' => $conversionUnit, 'description' => $conversionGroup['Unit Name'] ); } } return $conversionGroups; } // function getConversionGroupUnitDetails() /** * getConversionMultipliers * Returns an array of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM() * * @return array of mixed */ public static function getConversionMultipliers() { return self::$_conversionMultipliers; } // function getConversionGroups() /** * CONVERTUOM * * Converts a number from one measurement system to another. * For example, CONVERT can translate a table of distances in miles to a table of distances * in kilometers. * * Excel Function: * CONVERT(value,fromUOM,toUOM) * * @param float $value The value in fromUOM to convert. * @param string $fromUOM The units for value. * @param string $toUOM The units for the result. * * @return float */ public static function CONVERTUOM($value, $fromUOM, $toUOM) { $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $fromUOM = PHPExcel_Calculation_Functions::flattenSingleValue($fromUOM); $toUOM = PHPExcel_Calculation_Functions::flattenSingleValue($toUOM); if (!is_numeric($value)) { return PHPExcel_Calculation_Functions::VALUE(); } $fromMultiplier = 1.0; if (isset(self::$_conversionUnits[$fromUOM])) { $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group']; } else { $fromMultiplier = substr($fromUOM,0,1); $fromUOM = substr($fromUOM,1); if (isset(self::$_conversionMultipliers[$fromMultiplier])) { $fromMultiplier = self::$_conversionMultipliers[$fromMultiplier]['multiplier']; } else { return PHPExcel_Calculation_Functions::NA(); } if ((isset(self::$_conversionUnits[$fromUOM])) && (self::$_conversionUnits[$fromUOM]['AllowPrefix'])) { $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group']; } else { return PHPExcel_Calculation_Functions::NA(); } } $value *= $fromMultiplier; $toMultiplier = 1.0; if (isset(self::$_conversionUnits[$toUOM])) { $unitGroup2 = self::$_conversionUnits[$toUOM]['Group']; } else { $toMultiplier = substr($toUOM,0,1); $toUOM = substr($toUOM,1); if (isset(self::$_conversionMultipliers[$toMultiplier])) { $toMultiplier = self::$_conversionMultipliers[$toMultiplier]['multiplier']; } else { return PHPExcel_Calculation_Functions::NA(); } if ((isset(self::$_conversionUnits[$toUOM])) && (self::$_conversionUnits[$toUOM]['AllowPrefix'])) { $unitGroup2 = self::$_conversionUnits[$toUOM]['Group']; } else { return PHPExcel_Calculation_Functions::NA(); } } if ($unitGroup1 != $unitGroup2) { return PHPExcel_Calculation_Functions::NA(); } if (($fromUOM == $toUOM) && ($fromMultiplier == $toMultiplier)) { // We've already factored $fromMultiplier into the value, so we need // to reverse it again return $value / $fromMultiplier; } elseif ($unitGroup1 == 'Temperature') { if (($fromUOM == 'F') || ($fromUOM == 'fah')) { if (($toUOM == 'F') || ($toUOM == 'fah')) { return $value; } else { $value = (($value - 32) / 1.8); if (($toUOM == 'K') || ($toUOM == 'kel')) { $value += 273.15; } return $value; } } elseif ((($fromUOM == 'K') || ($fromUOM == 'kel')) && (($toUOM == 'K') || ($toUOM == 'kel'))) { return $value; } elseif ((($fromUOM == 'C') || ($fromUOM == 'cel')) && (($toUOM == 'C') || ($toUOM == 'cel'))) { return $value; } if (($toUOM == 'F') || ($toUOM == 'fah')) { if (($fromUOM == 'K') || ($fromUOM == 'kel')) { $value -= 273.15; } return ($value * 1.8) + 32; } if (($toUOM == 'C') || ($toUOM == 'cel')) { return $value - 273.15; } return $value + 273.15; } return ($value * self::$_unitConversions[$unitGroup1][$fromUOM][$toUOM]) / $toMultiplier; } // function CONVERTUOM() } // class PHPExcel_Calculation_Engineering PK ! %Dρ % PHPExcel/Calculation/functionlist.txtnu [ ABS ACCRINT ACCRINTM ACOS ACOSH ADDRESS AMORDEGRC AMORLINC AND AREAS ASC ASIN ASINH ATAN ATAN2 ATANH AVEDEV AVERAGE AVERAGEA AVERAGEIF AVERAGEIFS BAHTTEXT BESSELI BESSELJ BESSELK BESSELY BETADIST BETAINV BIN2DEC BIN2HEX BIN2OCT BINOMDIST CEILING CELL CHAR CHIDIST CHIINV CHITEST CHOOSE CLEAN CODE COLUMN COLUMNS COMBIN COMPLEX CONCATENATE CONFIDENCE CONVERT CORREL COS COSH COUNT COUNTA COUNTBLANK COUNTIF COUNTIFS COUPDAYBS COUPDAYBS COUPDAYSNC COUPNCD COUPNUM COUPPCD COVAR CRITBINOM CUBEKPIMEMBER CUBEMEMBER CUBEMEMBERPROPERTY CUBERANKEDMEMBER CUBESET CUBESETCOUNT CUBEVALUE CUMIPMT CUMPRINC DATE DATEDIF DATEVALUE DAVERAGE DAY DAYS360 DB DCOUNT DCOUNTA DDB DEC2BIN DEC2HEX DEC2OCT DEGREES DELTA DEVSQ DGET DISC DMAX DMIN DOLLAR DOLLARDE DOLLARFR DPRODUCT DSTDEV DSTDEVP DSUM DURATION DVAR DVARP EDATE EFFECT EOMONTH ERF ERFC ERROR.TYPE EVEN EXACT EXP EXPONDIST FACT FACTDOUBLE FALSE FDIST FIND FINDB FINV FISHER FISHERINV FIXED FLOOR FORECAST FREQUENCY FTEST FV FVSCHEDULE GAMAMDIST GAMMAINV GAMMALN GCD GEOMEAN GESTEP GETPIVOTDATA GROWTH HARMEAN HEX2BIN HEX2OCT HLOOKUP HOUR HYPERLINK HYPGEOMDIST IF IFERROR IMABS IMAGINARY IMARGUMENT IMCONJUGATE IMCOS IMEXP IMLN IMLOG10 IMLOG2 IMPOWER IMPRODUCT IMREAL IMSIN IMSQRT IMSUB IMSUM INDEX INDIRECT INFO INT INTERCEPT INTRATE IPMT IRR ISBLANK ISERR ISERROR ISEVEN ISLOGICAL ISNA ISNONTEXT ISNUMBER ISODD ISPMT ISREF ISTEXT JIS KURT LARGE LCM LEFT LEFTB LEN LENB LINEST LN LOG LOG10 LOGEST LOGINV LOGNORMDIST LOOKUP LOWER MATCH MAX MAXA MDETERM MDURATION MEDIAN MID MIDB MIN MINA MINUTE MINVERSE MIRR MMULT MOD MODE MONTH MROUND MULTINOMIAL N NA NEGBINOMDIST NETWORKDAYS NOMINAL NORMDIST NORMINV NORMSDIST NORMSINV NOT NOW NPER NPV OCT2BIN OCT2DEC OCT2HEX ODD ODDFPRICE ODDFYIELD ODDLPRICE ODDLYIELD OFFSET OR PEARSON PERCENTILE PERCENTRANK PERMUT PHONETIC PI PMT POISSON POWER PPMT PRICE PRICEDISC PRICEMAT PROB PRODUCT PROPER PV QUARTILE QUOTIENT RADIANS RAND RANDBETWEEN RANK RATE RECEIVED REPLACE REPLACEB REPT RIGHT RIGHTB ROMAN ROUND ROUNDDOWN ROUNDUP ROW ROWS RSQ RTD SEARCH SEARCHB SECOND SERIESSUM SIGN SIN SINH SKEW SLN SLOPE SMALL SQRT SQRTPI STANDARDIZE STDEV STDEVA STDEVP STDEVPA STEYX SUBSTITUTE SUBTOTAL SUM SUMIF SUMIFS SUMPRODUCT SUMSQ SUMX2MY2 SUMX2PY2 SUMXMY2 SYD T TAN TANH TBILLEQ TBILLPRICE TBILLYIELD TDIST TEXT TIME TIMEVALUE TINV TODAY TRANSPOSE TREND TRIM TRIMMEAN TRUE TRUNC TTEST TYPE UPPER USDOLLAR VALUE VAR VARA VARP VARPA VDB VERSION VLOOKUP WEEKDAY WEEKNUM WEIBULL WORKDAY XIRR XNPV YEAR YEARFRAC YIELD YIELDDISC YIELDMAT ZTEST PK ! MM ! PHPExcel/Calculation/DateTime.phpnu [ format('m'); $oYear = (int) $PHPDateObject->format('Y'); $adjustmentMonthsString = (string) $adjustmentMonths; if ($adjustmentMonths > 0) { $adjustmentMonthsString = '+'.$adjustmentMonths; } if ($adjustmentMonths != 0) { $PHPDateObject->modify($adjustmentMonthsString.' months'); } $nMonth = (int) $PHPDateObject->format('m'); $nYear = (int) $PHPDateObject->format('Y'); $monthDiff = ($nMonth - $oMonth) + (($nYear - $oYear) * 12); if ($monthDiff != $adjustmentMonths) { $adjustDays = (int) $PHPDateObject->format('d'); $adjustDaysString = '-'.$adjustDays.' days'; $PHPDateObject->modify($adjustDaysString); } return $PHPDateObject; } // function _adjustDateByMonths() /** * DATETIMENOW * * Returns the current date and time. * The NOW function is useful when you need to display the current date and time on a worksheet or * calculate a value based on the current date and time, and have that value updated each time you * open the worksheet. * * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date * and time format of your regional settings. PHPExcel does not change cell formatting in this way. * * Excel Function: * NOW() * * @access public * @category Date/Time Functions * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function DATETIMENOW() { $saveTimeZone = date_default_timezone_get(); date_default_timezone_set('UTC'); $retValue = False; switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL : $retValue = (float) PHPExcel_Shared_Date::PHPToExcel(time()); break; case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC : $retValue = (integer) time(); break; case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT : $retValue = new DateTime(); break; } date_default_timezone_set($saveTimeZone); return $retValue; } // function DATETIMENOW() /** * DATENOW * * Returns the current date. * The NOW function is useful when you need to display the current date and time on a worksheet or * calculate a value based on the current date and time, and have that value updated each time you * open the worksheet. * * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date * and time format of your regional settings. PHPExcel does not change cell formatting in this way. * * Excel Function: * TODAY() * * @access public * @category Date/Time Functions * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function DATENOW() { $saveTimeZone = date_default_timezone_get(); date_default_timezone_set('UTC'); $retValue = False; $excelDateTime = floor(PHPExcel_Shared_Date::PHPToExcel(time())); switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL : $retValue = (float) $excelDateTime; break; case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC : $retValue = (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateTime); break; case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT : $retValue = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateTime); break; } date_default_timezone_set($saveTimeZone); return $retValue; } // function DATENOW() /** * DATE * * The DATE function returns a value that represents a particular date. * * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date * format of your regional settings. PHPExcel does not change cell formatting in this way. * * Excel Function: * DATE(year,month,day) * * PHPExcel is a lot more forgiving than MS Excel when passing non numeric values to this function. * A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted, * as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language. * * @access public * @category Date/Time Functions * @param integer $year The value of the year argument can include one to four digits. * Excel interprets the year argument according to the configured * date system: 1900 or 1904. * If year is between 0 (zero) and 1899 (inclusive), Excel adds that * value to 1900 to calculate the year. For example, DATE(108,1,2) * returns January 2, 2008 (1900+108). * If year is between 1900 and 9999 (inclusive), Excel uses that * value as the year. For example, DATE(2008,1,2) returns January 2, * 2008. * If year is less than 0 or is 10000 or greater, Excel returns the * #NUM! error value. * @param integer $month A positive or negative integer representing the month of the year * from 1 to 12 (January to December). * If month is greater than 12, month adds that number of months to * the first month in the year specified. For example, DATE(2008,14,2) * returns the serial number representing February 2, 2009. * If month is less than 1, month subtracts the magnitude of that * number of months, plus 1, from the first month in the year * specified. For example, DATE(2008,-3,2) returns the serial number * representing September 2, 2007. * @param integer $day A positive or negative integer representing the day of the month * from 1 to 31. * If day is greater than the number of days in the month specified, * day adds that number of days to the first day in the month. For * example, DATE(2008,1,35) returns the serial number representing * February 4, 2008. * If day is less than 1, day subtracts the magnitude that number of * days, plus one, from the first day of the month specified. For * example, DATE(2008,1,-15) returns the serial number representing * December 16, 2007. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function DATE($year = 0, $month = 1, $day = 1) { $year = PHPExcel_Calculation_Functions::flattenSingleValue($year); $month = PHPExcel_Calculation_Functions::flattenSingleValue($month); $day = PHPExcel_Calculation_Functions::flattenSingleValue($day); if (($month !== NULL) && (!is_numeric($month))) { $month = PHPExcel_Shared_Date::monthStringToNumber($month); } if (($day !== NULL) && (!is_numeric($day))) { $day = PHPExcel_Shared_Date::dayStringToNumber($day); } $year = ($year !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($year) : 0; $month = ($month !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($month) : 0; $day = ($day !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($day) : 0; if ((!is_numeric($year)) || (!is_numeric($month)) || (!is_numeric($day))) { return PHPExcel_Calculation_Functions::VALUE(); } $year = (integer) $year; $month = (integer) $month; $day = (integer) $day; $baseYear = PHPExcel_Shared_Date::getExcelCalendar(); // Validate parameters if ($year < ($baseYear-1900)) { return PHPExcel_Calculation_Functions::NaN(); } if ((($baseYear-1900) != 0) && ($year < $baseYear) && ($year >= 1900)) { return PHPExcel_Calculation_Functions::NaN(); } if (($year < $baseYear) && ($year >= ($baseYear-1900))) { $year += 1900; } if ($month < 1) { // Handle year/month adjustment if month < 1 --$month; $year += ceil($month / 12) - 1; $month = 13 - abs($month % 12); } elseif ($month > 12) { // Handle year/month adjustment if month > 12 $year += floor($month / 12); $month = ($month % 12); } // Re-validate the year parameter after adjustments if (($year < $baseYear) || ($year >= 10000)) { return PHPExcel_Calculation_Functions::NaN(); } // Execute function $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year, $month, $day); switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL : return (float) $excelDateValue; case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC : return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue); case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT : return PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue); } } // function DATE() /** * TIME * * The TIME function returns a value that represents a particular time. * * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time * format of your regional settings. PHPExcel does not change cell formatting in this way. * * Excel Function: * TIME(hour,minute,second) * * @access public * @category Date/Time Functions * @param integer $hour A number from 0 (zero) to 32767 representing the hour. * Any value greater than 23 will be divided by 24 and the remainder * will be treated as the hour value. For example, TIME(27,0,0) = * TIME(3,0,0) = .125 or 3:00 AM. * @param integer $minute A number from 0 to 32767 representing the minute. * Any value greater than 59 will be converted to hours and minutes. * For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM. * @param integer $second A number from 0 to 32767 representing the second. * Any value greater than 59 will be converted to hours, minutes, * and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148 * or 12:33:20 AM * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function TIME($hour = 0, $minute = 0, $second = 0) { $hour = PHPExcel_Calculation_Functions::flattenSingleValue($hour); $minute = PHPExcel_Calculation_Functions::flattenSingleValue($minute); $second = PHPExcel_Calculation_Functions::flattenSingleValue($second); if ($hour == '') { $hour = 0; } if ($minute == '') { $minute = 0; } if ($second == '') { $second = 0; } if ((!is_numeric($hour)) || (!is_numeric($minute)) || (!is_numeric($second))) { return PHPExcel_Calculation_Functions::VALUE(); } $hour = (integer) $hour; $minute = (integer) $minute; $second = (integer) $second; if ($second < 0) { $minute += floor($second / 60); $second = 60 - abs($second % 60); if ($second == 60) { $second = 0; } } elseif ($second >= 60) { $minute += floor($second / 60); $second = $second % 60; } if ($minute < 0) { $hour += floor($minute / 60); $minute = 60 - abs($minute % 60); if ($minute == 60) { $minute = 0; } } elseif ($minute >= 60) { $hour += floor($minute / 60); $minute = $minute % 60; } if ($hour > 23) { $hour = $hour % 24; } elseif ($hour < 0) { return PHPExcel_Calculation_Functions::NaN(); } // Execute function switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL : $date = 0; $calendar = PHPExcel_Shared_Date::getExcelCalendar(); if ($calendar != PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900) { $date = 1; } return (float) PHPExcel_Shared_Date::FormattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second); case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC : return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::FormattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600 case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT : $dayAdjust = 0; if ($hour < 0) { $dayAdjust = floor($hour / 24); $hour = 24 - abs($hour % 24); if ($hour == 24) { $hour = 0; } } elseif ($hour >= 24) { $dayAdjust = floor($hour / 24); $hour = $hour % 24; } $phpDateObject = new DateTime('1900-01-01 '.$hour.':'.$minute.':'.$second); if ($dayAdjust != 0) { $phpDateObject->modify($dayAdjust.' days'); } return $phpDateObject; } } // function TIME() /** * DATEVALUE * * Returns a value that represents a particular date. * Use DATEVALUE to convert a date represented by a text string to an Excel or PHP date/time stamp * value. * * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date * format of your regional settings. PHPExcel does not change cell formatting in this way. * * Excel Function: * DATEVALUE(dateValue) * * @access public * @category Date/Time Functions * @param string $dateValue Text that represents a date in a Microsoft Excel date format. * For example, "1/30/2008" or "30-Jan-2008" are text strings within * quotation marks that represent dates. Using the default date * system in Excel for Windows, date_text must represent a date from * January 1, 1900, to December 31, 9999. Using the default date * system in Excel for the Macintosh, date_text must represent a date * from January 1, 1904, to December 31, 9999. DATEVALUE returns the * #VALUE! error value if date_text is out of this range. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function DATEVALUE($dateValue = 1) { $dateValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($dateValue),'"'); // Strip any ordinals because they're allowed in Excel (English only) $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui','$1$3',$dateValue); // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany) $dateValue = str_replace(array('/','.','-',' '),array(' ',' ',' ',' '),$dateValue); $yearFound = false; $t1 = explode(' ',$dateValue); foreach($t1 as &$t) { if ((is_numeric($t)) && ($t > 31)) { if ($yearFound) { return PHPExcel_Calculation_Functions::VALUE(); } else { if ($t < 100) { $t += 1900; } $yearFound = true; } } } if ((count($t1) == 1) && (strpos($t,':') != false)) { // We've been fed a time value without any date return 0.0; } elseif (count($t1) == 2) { // We only have two parts of the date: either day/month or month/year if ($yearFound) { array_unshift($t1,1); } else { array_push($t1,date('Y')); } } unset($t); $dateValue = implode(' ',$t1); $PHPDateArray = date_parse($dateValue); if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) { $testVal1 = strtok($dateValue,'- '); if ($testVal1 !== False) { $testVal2 = strtok('- '); if ($testVal2 !== False) { $testVal3 = strtok('- '); if ($testVal3 === False) { $testVal3 = strftime('%Y'); } } else { return PHPExcel_Calculation_Functions::VALUE(); } } else { return PHPExcel_Calculation_Functions::VALUE(); } $PHPDateArray = date_parse($testVal1.'-'.$testVal2.'-'.$testVal3); if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) { $PHPDateArray = date_parse($testVal2.'-'.$testVal1.'-'.$testVal3); if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) { return PHPExcel_Calculation_Functions::VALUE(); } } } if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) { // Execute function if ($PHPDateArray['year'] == '') { $PHPDateArray['year'] = strftime('%Y'); } if ($PHPDateArray['year'] < 1900) return PHPExcel_Calculation_Functions::VALUE(); if ($PHPDateArray['month'] == '') { $PHPDateArray['month'] = strftime('%m'); } if ($PHPDateArray['day'] == '') { $PHPDateArray['day'] = strftime('%d'); } $excelDateValue = floor(PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'],$PHPDateArray['month'],$PHPDateArray['day'],$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second'])); switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL : return (float) $excelDateValue; case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC : return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue); case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT : return new DateTime($PHPDateArray['year'].'-'.$PHPDateArray['month'].'-'.$PHPDateArray['day'].' 00:00:00'); } } return PHPExcel_Calculation_Functions::VALUE(); } // function DATEVALUE() /** * TIMEVALUE * * Returns a value that represents a particular time. * Use TIMEVALUE to convert a time represented by a text string to an Excel or PHP date/time stamp * value. * * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time * format of your regional settings. PHPExcel does not change cell formatting in this way. * * Excel Function: * TIMEVALUE(timeValue) * * @access public * @category Date/Time Functions * @param string $timeValue A text string that represents a time in any one of the Microsoft * Excel time formats; for example, "6:45 PM" and "18:45" text strings * within quotation marks that represent time. * Date information in time_text is ignored. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function TIMEVALUE($timeValue) { $timeValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($timeValue),'"'); $timeValue = str_replace(array('/','.'),array('-','-'),$timeValue); $PHPDateArray = date_parse($timeValue); if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'],$PHPDateArray['month'],$PHPDateArray['day'],$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']); } else { $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel(1900,1,1,$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']) - 1; } switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL : return (float) $excelDateValue; case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC : return (integer) $phpDateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue+25569) - 3600;; case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT : return new DateTime('1900-01-01 '.$PHPDateArray['hour'].':'.$PHPDateArray['minute'].':'.$PHPDateArray['second']); } } return PHPExcel_Calculation_Functions::VALUE(); } // function TIMEVALUE() /** * DATEDIF * * @param mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object * or a standard date string * @param mixed $endDate Excel date serial value, PHP date/time stamp, PHP DateTime object * or a standard date string * @param string $unit * @return integer Interval between the dates */ public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D') { $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate); $unit = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($unit)); if (is_string($startDate = self::_getDateValue($startDate))) { return PHPExcel_Calculation_Functions::VALUE(); } if (is_string($endDate = self::_getDateValue($endDate))) { return PHPExcel_Calculation_Functions::VALUE(); } // Validate parameters if ($startDate >= $endDate) { return PHPExcel_Calculation_Functions::NaN(); } // Execute function $difference = $endDate - $startDate; $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate); $startDays = $PHPStartDateObject->format('j'); $startMonths = $PHPStartDateObject->format('n'); $startYears = $PHPStartDateObject->format('Y'); $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate); $endDays = $PHPEndDateObject->format('j'); $endMonths = $PHPEndDateObject->format('n'); $endYears = $PHPEndDateObject->format('Y'); $retVal = PHPExcel_Calculation_Functions::NaN(); switch ($unit) { case 'D': $retVal = intval($difference); break; case 'M': $retVal = intval($endMonths - $startMonths) + (intval($endYears - $startYears) * 12); // We're only interested in full months if ($endDays < $startDays) { --$retVal; } break; case 'Y': $retVal = intval($endYears - $startYears); // We're only interested in full months if ($endMonths < $startMonths) { --$retVal; } elseif (($endMonths == $startMonths) && ($endDays < $startDays)) { --$retVal; } break; case 'MD': if ($endDays < $startDays) { $retVal = $endDays; $PHPEndDateObject->modify('-'.$endDays.' days'); $adjustDays = $PHPEndDateObject->format('j'); if ($adjustDays > $startDays) { $retVal += ($adjustDays - $startDays); } } else { $retVal = $endDays - $startDays; } break; case 'YM': $retVal = intval($endMonths - $startMonths); if ($retVal < 0) $retVal = 12 + $retVal; // We're only interested in full months if ($endDays < $startDays) { --$retVal; } break; case 'YD': $retVal = intval($difference); if ($endYears > $startYears) { while ($endYears > $startYears) { $PHPEndDateObject->modify('-1 year'); $endYears = $PHPEndDateObject->format('Y'); } $retVal = $PHPEndDateObject->format('z') - $PHPStartDateObject->format('z'); if ($retVal < 0) { $retVal += 365; } } break; default: $retVal = PHPExcel_Calculation_Functions::NaN(); } return $retVal; } // function DATEDIF() /** * DAYS360 * * Returns the number of days between two dates based on a 360-day year (twelve 30-day months), * which is used in some accounting calculations. Use this function to help compute payments if * your accounting system is based on twelve 30-day months. * * Excel Function: * DAYS360(startDate,endDate[,method]) * * @access public * @category Date/Time Functions * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param boolean $method US or European Method * FALSE or omitted: U.S. (NASD) method. If the starting date is * the last day of a month, it becomes equal to the 30th of the * same month. If the ending date is the last day of a month and * the starting date is earlier than the 30th of a month, the * ending date becomes equal to the 1st of the next month; * otherwise the ending date becomes equal to the 30th of the * same month. * TRUE: European method. Starting dates and ending dates that * occur on the 31st of a month become equal to the 30th of the * same month. * @return integer Number of days between start date and end date */ public static function DAYS360($startDate = 0, $endDate = 0, $method = false) { $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate); if (is_string($startDate = self::_getDateValue($startDate))) { return PHPExcel_Calculation_Functions::VALUE(); } if (is_string($endDate = self::_getDateValue($endDate))) { return PHPExcel_Calculation_Functions::VALUE(); } if (!is_bool($method)) { return PHPExcel_Calculation_Functions::VALUE(); } // Execute function $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate); $startDay = $PHPStartDateObject->format('j'); $startMonth = $PHPStartDateObject->format('n'); $startYear = $PHPStartDateObject->format('Y'); $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate); $endDay = $PHPEndDateObject->format('j'); $endMonth = $PHPEndDateObject->format('n'); $endYear = $PHPEndDateObject->format('Y'); return self::_dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, !$method); } // function DAYS360() /** * YEARFRAC * * Calculates the fraction of the year represented by the number of whole days between two dates * (the start_date and the end_date). * Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or * obligations to assign to a specific term. * * Excel Function: * YEARFRAC(startDate,endDate[,method]) * * @access public * @category Date/Time Functions * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param integer $method Method used for the calculation * 0 or omitted US (NASD) 30/360 * 1 Actual/actual * 2 Actual/360 * 3 Actual/365 * 4 European 30/360 * @return float fraction of the year */ public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0) { $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate); $method = PHPExcel_Calculation_Functions::flattenSingleValue($method); if (is_string($startDate = self::_getDateValue($startDate))) { return PHPExcel_Calculation_Functions::VALUE(); } if (is_string($endDate = self::_getDateValue($endDate))) { return PHPExcel_Calculation_Functions::VALUE(); } if (((is_numeric($method)) && (!is_string($method))) || ($method == '')) { switch($method) { case 0 : return self::DAYS360($startDate,$endDate) / 360; case 1 : $days = self::DATEDIF($startDate,$endDate); $startYear = self::YEAR($startDate); $endYear = self::YEAR($endDate); $years = $endYear - $startYear + 1; $leapDays = 0; if ($years == 1) { if (self::_isLeapYear($endYear)) { $startMonth = self::MONTHOFYEAR($startDate); $endMonth = self::MONTHOFYEAR($endDate); $endDay = self::DAYOFMONTH($endDate); if (($startMonth < 3) || (($endMonth * 100 + $endDay) >= (2 * 100 + 29))) { $leapDays += 1; } } } else { for($year = $startYear; $year <= $endYear; ++$year) { if ($year == $startYear) { $startMonth = self::MONTHOFYEAR($startDate); $startDay = self::DAYOFMONTH($startDate); if ($startMonth < 3) { $leapDays += (self::_isLeapYear($year)) ? 1 : 0; } } elseif($year == $endYear) { $endMonth = self::MONTHOFYEAR($endDate); $endDay = self::DAYOFMONTH($endDate); if (($endMonth * 100 + $endDay) >= (2 * 100 + 29)) { $leapDays += (self::_isLeapYear($year)) ? 1 : 0; } } else { $leapDays += (self::_isLeapYear($year)) ? 1 : 0; } } if ($years == 2) { if (($leapDays == 0) && (self::_isLeapYear($startYear)) && ($days > 365)) { $leapDays = 1; } elseif ($days < 366) { $years = 1; } } $leapDays /= $years; } return $days / (365 + $leapDays); case 2 : return self::DATEDIF($startDate,$endDate) / 360; case 3 : return self::DATEDIF($startDate,$endDate) / 365; case 4 : return self::DAYS360($startDate,$endDate,True) / 360; } } return PHPExcel_Calculation_Functions::VALUE(); } // function YEARFRAC() /** * NETWORKDAYS * * Returns the number of whole working days between start_date and end_date. Working days * exclude weekends and any dates identified in holidays. * Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days * worked during a specific term. * * Excel Function: * NETWORKDAYS(startDate,endDate[,holidays[,holiday[,...]]]) * * @access public * @category Date/Time Functions * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param mixed $holidays,... Optional series of Excel date serial value (float), PHP date * timestamp (integer), PHP DateTime object, or a standard date * strings that will be excluded from the working calendar, such * as state and federal holidays and floating holidays. * @return integer Interval between the dates */ public static function NETWORKDAYS($startDate,$endDate) { // Retrieve the mandatory start and end date that are referenced in the function definition $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate); // Flush the mandatory start and end date that are referenced in the function definition, and get the optional days $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); array_shift($dateArgs); array_shift($dateArgs); // Validate the start and end dates if (is_string($startDate = $sDate = self::_getDateValue($startDate))) { return PHPExcel_Calculation_Functions::VALUE(); } $startDate = (float) floor($startDate); if (is_string($endDate = $eDate = self::_getDateValue($endDate))) { return PHPExcel_Calculation_Functions::VALUE(); } $endDate = (float) floor($endDate); if ($sDate > $eDate) { $startDate = $eDate; $endDate = $sDate; } // Execute function $startDoW = 6 - self::DAYOFWEEK($startDate,2); if ($startDoW < 0) { $startDoW = 0; } $endDoW = self::DAYOFWEEK($endDate,2); if ($endDoW >= 6) { $endDoW = 0; } $wholeWeekDays = floor(($endDate - $startDate) / 7) * 5; $partWeekDays = $endDoW + $startDoW; if ($partWeekDays > 5) { $partWeekDays -= 5; } // Test any extra holiday parameters $holidayCountedArray = array(); foreach ($dateArgs as $holidayDate) { if (is_string($holidayDate = self::_getDateValue($holidayDate))) { return PHPExcel_Calculation_Functions::VALUE(); } if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) { if ((self::DAYOFWEEK($holidayDate,2) < 6) && (!in_array($holidayDate,$holidayCountedArray))) { --$partWeekDays; $holidayCountedArray[] = $holidayDate; } } } if ($sDate > $eDate) { return 0 - ($wholeWeekDays + $partWeekDays); } return $wholeWeekDays + $partWeekDays; } // function NETWORKDAYS() /** * WORKDAY * * Returns the date that is the indicated number of working days before or after a date (the * starting date). Working days exclude weekends and any dates identified as holidays. * Use WORKDAY to exclude weekends or holidays when you calculate invoice due dates, expected * delivery times, or the number of days of work performed. * * Excel Function: * WORKDAY(startDate,endDays[,holidays[,holiday[,...]]]) * * @access public * @category Date/Time Functions * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param integer $endDays The number of nonweekend and nonholiday days before or after * startDate. A positive value for days yields a future date; a * negative value yields a past date. * @param mixed $holidays,... Optional series of Excel date serial value (float), PHP date * timestamp (integer), PHP DateTime object, or a standard date * strings that will be excluded from the working calendar, such * as state and federal holidays and floating holidays. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function WORKDAY($startDate,$endDays) { // Retrieve the mandatory start date and days that are referenced in the function definition $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $endDays = PHPExcel_Calculation_Functions::flattenSingleValue($endDays); // Flush the mandatory start date and days that are referenced in the function definition, and get the optional days $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); array_shift($dateArgs); array_shift($dateArgs); if ((is_string($startDate = self::_getDateValue($startDate))) || (!is_numeric($endDays))) { return PHPExcel_Calculation_Functions::VALUE(); } $startDate = (float) floor($startDate); $endDays = (int) floor($endDays); // If endDays is 0, we always return startDate if ($endDays == 0) { return $startDate; } $decrementing = ($endDays < 0) ? True : False; // Adjust the start date if it falls over a weekend $startDoW = self::DAYOFWEEK($startDate,3); if (self::DAYOFWEEK($startDate,3) >= 5) { $startDate += ($decrementing) ? -$startDoW + 4: 7 - $startDoW; ($decrementing) ? $endDays++ : $endDays--; } // Add endDays $endDate = (float) $startDate + (intval($endDays / 5) * 7) + ($endDays % 5); // Adjust the calculated end date if it falls over a weekend $endDoW = self::DAYOFWEEK($endDate,3); if ($endDoW >= 5) { $endDate += ($decrementing) ? -$endDoW + 4: 7 - $endDoW; } // Test any extra holiday parameters if (!empty($dateArgs)) { $holidayCountedArray = $holidayDates = array(); foreach ($dateArgs as $holidayDate) { if (($holidayDate !== NULL) && (trim($holidayDate) > '')) { if (is_string($holidayDate = self::_getDateValue($holidayDate))) { return PHPExcel_Calculation_Functions::VALUE(); } if (self::DAYOFWEEK($holidayDate,3) < 5) { $holidayDates[] = $holidayDate; } } } if ($decrementing) { rsort($holidayDates, SORT_NUMERIC); } else { sort($holidayDates, SORT_NUMERIC); } foreach ($holidayDates as $holidayDate) { if ($decrementing) { if (($holidayDate <= $startDate) && ($holidayDate >= $endDate)) { if (!in_array($holidayDate,$holidayCountedArray)) { --$endDate; $holidayCountedArray[] = $holidayDate; } } } else { if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) { if (!in_array($holidayDate,$holidayCountedArray)) { ++$endDate; $holidayCountedArray[] = $holidayDate; } } } // Adjust the calculated end date if it falls over a weekend $endDoW = self::DAYOFWEEK($endDate,3); if ($endDoW >= 5) { $endDate += ($decrementing) ? -$endDoW + 4: 7 - $endDoW; } } } switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL : return (float) $endDate; case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC : return (integer) PHPExcel_Shared_Date::ExcelToPHP($endDate); case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT : return PHPExcel_Shared_Date::ExcelToPHPObject($endDate); } } // function WORKDAY() /** * DAYOFMONTH * * Returns the day of the month, for a specified date. The day is given as an integer * ranging from 1 to 31. * * Excel Function: * DAY(dateValue) * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @return int Day of the month */ public static function DAYOFMONTH($dateValue = 1) { $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); if (is_string($dateValue = self::_getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue == 0.0) { return 0; } elseif ($dateValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); } // Execute function $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue); return (int) $PHPDateObject->format('j'); } // function DAYOFMONTH() /** * DAYOFWEEK * * Returns the day of the week for a specified date. The day is given as an integer * ranging from 0 to 7 (dependent on the requested style). * * Excel Function: * WEEKDAY(dateValue[,style]) * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param int $style A number that determines the type of return value * 1 or omitted Numbers 1 (Sunday) through 7 (Saturday). * 2 Numbers 1 (Monday) through 7 (Sunday). * 3 Numbers 0 (Monday) through 6 (Sunday). * @return int Day of the week value */ public static function DAYOFWEEK($dateValue = 1, $style = 1) { $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $style = PHPExcel_Calculation_Functions::flattenSingleValue($style); if (!is_numeric($style)) { return PHPExcel_Calculation_Functions::VALUE(); } elseif (($style < 1) || ($style > 3)) { return PHPExcel_Calculation_Functions::NaN(); } $style = floor($style); if (is_string($dateValue = self::_getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); } // Execute function $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue); $DoW = $PHPDateObject->format('w'); $firstDay = 1; switch ($style) { case 1: ++$DoW; break; case 2: if ($DoW == 0) { $DoW = 7; } break; case 3: if ($DoW == 0) { $DoW = 7; } $firstDay = 0; --$DoW; break; } if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL) { // Test for Excel's 1900 leap year, and introduce the error as required if (($PHPDateObject->format('Y') == 1900) && ($PHPDateObject->format('n') <= 2)) { --$DoW; if ($DoW < $firstDay) { $DoW += 7; } } } return (int) $DoW; } // function DAYOFWEEK() /** * WEEKOFYEAR * * Returns the week of the year for a specified date. * The WEEKNUM function considers the week containing January 1 to be the first week of the year. * However, there is a European standard that defines the first week as the one with the majority * of days (four or more) falling in the new year. This means that for years in which there are * three days or less in the first week of January, the WEEKNUM function returns week numbers * that are incorrect according to the European standard. * * Excel Function: * WEEKNUM(dateValue[,style]) * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param boolean $method Week begins on Sunday or Monday * 1 or omitted Week begins on Sunday. * 2 Week begins on Monday. * @return int Week Number */ public static function WEEKOFYEAR($dateValue = 1, $method = 1) { $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $method = PHPExcel_Calculation_Functions::flattenSingleValue($method); if (!is_numeric($method)) { return PHPExcel_Calculation_Functions::VALUE(); } elseif (($method < 1) || ($method > 2)) { return PHPExcel_Calculation_Functions::NaN(); } $method = floor($method); if (is_string($dateValue = self::_getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); } // Execute function $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue); $dayOfYear = $PHPDateObject->format('z'); $dow = $PHPDateObject->format('w'); $PHPDateObject->modify('-'.$dayOfYear.' days'); $dow = $PHPDateObject->format('w'); $daysInFirstWeek = 7 - (($dow + (2 - $method)) % 7); $dayOfYear -= $daysInFirstWeek; $weekOfYear = ceil($dayOfYear / 7) + 1; return (int) $weekOfYear; } // function WEEKOFYEAR() /** * MONTHOFYEAR * * Returns the month of a date represented by a serial number. * The month is given as an integer, ranging from 1 (January) to 12 (December). * * Excel Function: * MONTH(dateValue) * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @return int Month of the year */ public static function MONTHOFYEAR($dateValue = 1) { $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); if (is_string($dateValue = self::_getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); } // Execute function $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue); return (int) $PHPDateObject->format('n'); } // function MONTHOFYEAR() /** * YEAR * * Returns the year corresponding to a date. * The year is returned as an integer in the range 1900-9999. * * Excel Function: * YEAR(dateValue) * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @return int Year */ public static function YEAR($dateValue = 1) { $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); if (is_string($dateValue = self::_getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); } // Execute function $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue); return (int) $PHPDateObject->format('Y'); } // function YEAR() /** * HOUROFDAY * * Returns the hour of a time value. * The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.). * * Excel Function: * HOUR(timeValue) * * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard time string * @return int Hour */ public static function HOUROFDAY($timeValue = 0) { $timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue); if (!is_numeric($timeValue)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { $testVal = strtok($timeValue,'/-: '); if (strlen($testVal) < strlen($timeValue)) { return PHPExcel_Calculation_Functions::VALUE(); } } $timeValue = self::_getTimeValue($timeValue); if (is_string($timeValue)) { return PHPExcel_Calculation_Functions::VALUE(); } } // Execute function if ($timeValue >= 1) { $timeValue = fmod($timeValue,1); } elseif ($timeValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); } $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue); return (int) gmdate('G',$timeValue); } // function HOUROFDAY() /** * MINUTEOFHOUR * * Returns the minutes of a time value. * The minute is given as an integer, ranging from 0 to 59. * * Excel Function: * MINUTE(timeValue) * * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard time string * @return int Minute */ public static function MINUTEOFHOUR($timeValue = 0) { $timeValue = $timeTester = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue); if (!is_numeric($timeValue)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { $testVal = strtok($timeValue,'/-: '); if (strlen($testVal) < strlen($timeValue)) { return PHPExcel_Calculation_Functions::VALUE(); } } $timeValue = self::_getTimeValue($timeValue); if (is_string($timeValue)) { return PHPExcel_Calculation_Functions::VALUE(); } } // Execute function if ($timeValue >= 1) { $timeValue = fmod($timeValue,1); } elseif ($timeValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); } $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue); return (int) gmdate('i',$timeValue); } // function MINUTEOFHOUR() /** * SECONDOFMINUTE * * Returns the seconds of a time value. * The second is given as an integer in the range 0 (zero) to 59. * * Excel Function: * SECOND(timeValue) * * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard time string * @return int Second */ public static function SECONDOFMINUTE($timeValue = 0) { $timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue); if (!is_numeric($timeValue)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { $testVal = strtok($timeValue,'/-: '); if (strlen($testVal) < strlen($timeValue)) { return PHPExcel_Calculation_Functions::VALUE(); } } $timeValue = self::_getTimeValue($timeValue); if (is_string($timeValue)) { return PHPExcel_Calculation_Functions::VALUE(); } } // Execute function if ($timeValue >= 1) { $timeValue = fmod($timeValue,1); } elseif ($timeValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); } $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue); return (int) gmdate('s',$timeValue); } // function SECONDOFMINUTE() /** * EDATE * * Returns the serial number that represents the date that is the indicated number of months * before or after a specified date (the start_date). * Use EDATE to calculate maturity dates or due dates that fall on the same day of the month * as the date of issue. * * Excel Function: * EDATE(dateValue,adjustmentMonths) * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param int $adjustmentMonths The number of months before or after start_date. * A positive value for months yields a future date; * a negative value yields a past date. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function EDATE($dateValue = 1, $adjustmentMonths = 0) { $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths); if (!is_numeric($adjustmentMonths)) { return PHPExcel_Calculation_Functions::VALUE(); } $adjustmentMonths = floor($adjustmentMonths); if (is_string($dateValue = self::_getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } // Execute function $PHPDateObject = self::_adjustDateByMonths($dateValue,$adjustmentMonths); switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL : return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject); case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC : return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject)); case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT : return $PHPDateObject; } } // function EDATE() /** * EOMONTH * * Returns the date value for the last day of the month that is the indicated number of months * before or after start_date. * Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month. * * Excel Function: * EOMONTH(dateValue,adjustmentMonths) * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param int $adjustmentMonths The number of months before or after start_date. * A positive value for months yields a future date; * a negative value yields a past date. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0) { $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths); if (!is_numeric($adjustmentMonths)) { return PHPExcel_Calculation_Functions::VALUE(); } $adjustmentMonths = floor($adjustmentMonths); if (is_string($dateValue = self::_getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } // Execute function $PHPDateObject = self::_adjustDateByMonths($dateValue,$adjustmentMonths+1); $adjustDays = (int) $PHPDateObject->format('d'); $adjustDaysString = '-'.$adjustDays.' days'; $PHPDateObject->modify($adjustDaysString); switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL : return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject); case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC : return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject)); case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT : return $PHPDateObject; } } // function EOMONTH() } // class PHPExcel_Calculation_DateTime PK ! b % PHPExcel/Calculation/FormulaToken.phpnu [ _value = $pValue; $this->_tokenType = $pTokenType; $this->_tokenSubType = $pTokenSubType; } /** * Get Value * * @return string */ public function getValue() { return $this->_value; } /** * Set Value * * @param string $value */ public function setValue($value) { $this->_value = $value; } /** * Get Token Type (represented by TOKEN_TYPE_*) * * @return string */ public function getTokenType() { return $this->_tokenType; } /** * Set Token Type * * @param string $value */ public function setTokenType($value = PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN) { $this->_tokenType = $value; } /** * Get Token SubType (represented by TOKEN_SUBTYPE_*) * * @return string */ public function getTokenSubType() { return $this->_tokenSubType; } /** * Set Token SubType * * @param string $value */ public function setTokenSubType($value = PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { $this->_tokenSubType = $value; } } PK ! [ [ ! PHPExcel/Calculation/MathTrig.phpnu [ 1; --$i) { if (($value % $i) == 0) { $factorArray = array_merge($factorArray,self::_factors($value / $i)); $factorArray = array_merge($factorArray,self::_factors($i)); if ($i <= sqrt($value)) { break; } } } if (!empty($factorArray)) { rsort($factorArray); return $factorArray; } else { return array((integer) $value); } } // function _factors() private static function _romanCut($num, $n) { return ($num - ($num % $n ) ) / $n; } // function _romanCut() /** * ATAN2 * * This function calculates the arc tangent of the two variables x and y. It is similar to * calculating the arc tangent of y ÷ x, except that the signs of both arguments are used * to determine the quadrant of the result. * The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a * point with coordinates (xCoordinate, yCoordinate). The angle is given in radians between * -pi and pi, excluding -pi. * * Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard * PHP atan2() function, so we need to reverse them here before calling the PHP atan() function. * * Excel Function: * ATAN2(xCoordinate,yCoordinate) * * @access public * @category Mathematical and Trigonometric Functions * @param float $xCoordinate The x-coordinate of the point. * @param float $yCoordinate The y-coordinate of the point. * @return float The inverse tangent of the specified x- and y-coordinates. */ public static function ATAN2($xCoordinate = NULL, $yCoordinate = NULL) { $xCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($xCoordinate); $yCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($yCoordinate); $xCoordinate = ($xCoordinate !== NULL) ? $xCoordinate : 0.0; $yCoordinate = ($yCoordinate !== NULL) ? $yCoordinate : 0.0; if (((is_numeric($xCoordinate)) || (is_bool($xCoordinate))) && ((is_numeric($yCoordinate))) || (is_bool($yCoordinate))) { $xCoordinate = (float) $xCoordinate; $yCoordinate = (float) $yCoordinate; if (($xCoordinate == 0) && ($yCoordinate == 0)) { return PHPExcel_Calculation_Functions::DIV0(); } return atan2($yCoordinate, $xCoordinate); } return PHPExcel_Calculation_Functions::VALUE(); } // function ATAN2() /** * CEILING * * Returns number rounded up, away from zero, to the nearest multiple of significance. * For example, if you want to avoid using pennies in your prices and your product is * priced at $4.42, use the formula =CEILING(4.42,0.05) to round prices up to the * nearest nickel. * * Excel Function: * CEILING(number[,significance]) * * @access public * @category Mathematical and Trigonometric Functions * @param float $number The number you want to round. * @param float $significance The multiple to which you want to round. * @return float Rounded Number */ public static function CEILING($number, $significance = NULL) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance); if ((is_null($significance)) && (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) { $significance = $number/abs($number); } if ((is_numeric($number)) && (is_numeric($significance))) { if ($significance == 0.0) { return 0.0; } elseif (self::SIGN($number) == self::SIGN($significance)) { return ceil($number / $significance) * $significance; } else { return PHPExcel_Calculation_Functions::NaN(); } } return PHPExcel_Calculation_Functions::VALUE(); } // function CEILING() /** * COMBIN * * Returns the number of combinations for a given number of items. Use COMBIN to * determine the total possible number of groups for a given number of items. * * Excel Function: * COMBIN(numObjs,numInSet) * * @access public * @category Mathematical and Trigonometric Functions * @param int $numObjs Number of different objects * @param int $numInSet Number of objects in each combination * @return int Number of combinations */ public static function COMBIN($numObjs, $numInSet) { $numObjs = PHPExcel_Calculation_Functions::flattenSingleValue($numObjs); $numInSet = PHPExcel_Calculation_Functions::flattenSingleValue($numInSet); if ((is_numeric($numObjs)) && (is_numeric($numInSet))) { if ($numObjs < $numInSet) { return PHPExcel_Calculation_Functions::NaN(); } elseif ($numInSet < 0) { return PHPExcel_Calculation_Functions::NaN(); } return round(self::FACT($numObjs) / self::FACT($numObjs - $numInSet)) / self::FACT($numInSet); } return PHPExcel_Calculation_Functions::VALUE(); } // function COMBIN() /** * EVEN * * Returns number rounded up to the nearest even integer. * You can use this function for processing items that come in twos. For example, * a packing crate accepts rows of one or two items. The crate is full when * the number of items, rounded up to the nearest two, matches the crate's * capacity. * * Excel Function: * EVEN(number) * * @access public * @category Mathematical and Trigonometric Functions * @param float $number Number to round * @return int Rounded Number */ public static function EVEN($number) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); if (is_null($number)) { return 0; } elseif (is_bool($number)) { $number = (int) $number; } if (is_numeric($number)) { $significance = 2 * self::SIGN($number); return (int) self::CEILING($number,$significance); } return PHPExcel_Calculation_Functions::VALUE(); } // function EVEN() /** * FACT * * Returns the factorial of a number. * The factorial of a number is equal to 1*2*3*...* number. * * Excel Function: * FACT(factVal) * * @access public * @category Mathematical and Trigonometric Functions * @param float $factVal Factorial Value * @return int Factorial */ public static function FACT($factVal) { $factVal = PHPExcel_Calculation_Functions::flattenSingleValue($factVal); if (is_numeric($factVal)) { if ($factVal < 0) { return PHPExcel_Calculation_Functions::NaN(); } $factLoop = floor($factVal); if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { if ($factVal > $factLoop) { return PHPExcel_Calculation_Functions::NaN(); } } $factorial = 1; while ($factLoop > 1) { $factorial *= $factLoop--; } return $factorial ; } return PHPExcel_Calculation_Functions::VALUE(); } // function FACT() /** * FACTDOUBLE * * Returns the double factorial of a number. * * Excel Function: * FACTDOUBLE(factVal) * * @access public * @category Mathematical and Trigonometric Functions * @param float $factVal Factorial Value * @return int Double Factorial */ public static function FACTDOUBLE($factVal) { $factLoop = PHPExcel_Calculation_Functions::flattenSingleValue($factVal); if (is_numeric($factLoop)) { $factLoop = floor($factLoop); if ($factVal < 0) { return PHPExcel_Calculation_Functions::NaN(); } $factorial = 1; while ($factLoop > 1) { $factorial *= $factLoop--; --$factLoop; } return $factorial ; } return PHPExcel_Calculation_Functions::VALUE(); } // function FACTDOUBLE() /** * FLOOR * * Rounds number down, toward zero, to the nearest multiple of significance. * * Excel Function: * FLOOR(number[,significance]) * * @access public * @category Mathematical and Trigonometric Functions * @param float $number Number to round * @param float $significance Significance * @return float Rounded Number */ public static function FLOOR($number, $significance = NULL) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance); if ((is_null($significance)) && (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) { $significance = $number/abs($number); } if ((is_numeric($number)) && (is_numeric($significance))) { if ((float) $significance == 0.0) { return PHPExcel_Calculation_Functions::DIV0(); } if (self::SIGN($number) == self::SIGN($significance)) { return floor($number / $significance) * $significance; } else { return PHPExcel_Calculation_Functions::NaN(); } } return PHPExcel_Calculation_Functions::VALUE(); } // function FLOOR() /** * GCD * * Returns the greatest common divisor of a series of numbers. * The greatest common divisor is the largest integer that divides both * number1 and number2 without a remainder. * * Excel Function: * GCD(number1[,number2[, ...]]) * * @access public * @category Mathematical and Trigonometric Functions * @param mixed $arg,... Data values * @return integer Greatest Common Divisor */ public static function GCD() { $returnValue = 1; $allValuesFactors = array(); // Loop through arguments foreach(PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $value) { if (!is_numeric($value)) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($value == 0) { continue; } elseif($value < 0) { return PHPExcel_Calculation_Functions::NaN(); } $myFactors = self::_factors($value); $myCountedFactors = array_count_values($myFactors); $allValuesFactors[] = $myCountedFactors; } $allValuesCount = count($allValuesFactors); if ($allValuesCount == 0) { return 0; } $mergedArray = $allValuesFactors[0]; for ($i=1;$i < $allValuesCount; ++$i) { $mergedArray = array_intersect_key($mergedArray,$allValuesFactors[$i]); } $mergedArrayValues = count($mergedArray); if ($mergedArrayValues == 0) { return $returnValue; } elseif ($mergedArrayValues > 1) { foreach($mergedArray as $mergedKey => $mergedValue) { foreach($allValuesFactors as $highestPowerTest) { foreach($highestPowerTest as $testKey => $testValue) { if (($testKey == $mergedKey) && ($testValue < $mergedValue)) { $mergedArray[$mergedKey] = $testValue; $mergedValue = $testValue; } } } } $returnValue = 1; foreach($mergedArray as $key => $value) { $returnValue *= pow($key,$value); } return $returnValue; } else { $keys = array_keys($mergedArray); $key = $keys[0]; $value = $mergedArray[$key]; foreach($allValuesFactors as $testValue) { foreach($testValue as $mergedKey => $mergedValue) { if (($mergedKey == $key) && ($mergedValue < $value)) { $value = $mergedValue; } } } return pow($key,$value); } } // function GCD() /** * INT * * Casts a floating point value to an integer * * Excel Function: * INT(number) * * @access public * @category Mathematical and Trigonometric Functions * @param float $number Number to cast to an integer * @return integer Integer value */ public static function INT($number) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); if (is_null($number)) { return 0; } elseif (is_bool($number)) { return (int) $number; } if (is_numeric($number)) { return (int) floor($number); } return PHPExcel_Calculation_Functions::VALUE(); } // function INT() /** * LCM * * Returns the lowest common multiplier of a series of numbers * The least common multiple is the smallest positive integer that is a multiple * of all integer arguments number1, number2, and so on. Use LCM to add fractions * with different denominators. * * Excel Function: * LCM(number1[,number2[, ...]]) * * @access public * @category Mathematical and Trigonometric Functions * @param mixed $arg,... Data values * @return int Lowest Common Multiplier */ public static function LCM() { $returnValue = 1; $allPoweredFactors = array(); // Loop through arguments foreach(PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $value) { if (!is_numeric($value)) { return PHPExcel_Calculation_Functions::VALUE(); } if ($value == 0) { return 0; } elseif ($value < 0) { return PHPExcel_Calculation_Functions::NaN(); } $myFactors = self::_factors(floor($value)); $myCountedFactors = array_count_values($myFactors); $myPoweredFactors = array(); foreach($myCountedFactors as $myCountedFactor => $myCountedPower) { $myPoweredFactors[$myCountedFactor] = pow($myCountedFactor,$myCountedPower); } foreach($myPoweredFactors as $myPoweredValue => $myPoweredFactor) { if (array_key_exists($myPoweredValue,$allPoweredFactors)) { if ($allPoweredFactors[$myPoweredValue] < $myPoweredFactor) { $allPoweredFactors[$myPoweredValue] = $myPoweredFactor; } } else { $allPoweredFactors[$myPoweredValue] = $myPoweredFactor; } } } foreach($allPoweredFactors as $allPoweredFactor) { $returnValue *= (integer) $allPoweredFactor; } return $returnValue; } // function LCM() /** * LOG_BASE * * Returns the logarithm of a number to a specified base. The default base is 10. * * Excel Function: * LOG(number[,base]) * * @access public * @category Mathematical and Trigonometric Functions * @param float $number The positive real number for which you want the logarithm * @param float $base The base of the logarithm. If base is omitted, it is assumed to be 10. * @return float */ public static function LOG_BASE($number = NULL, $base = 10) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $base = (is_null($base)) ? 10 : (float) PHPExcel_Calculation_Functions::flattenSingleValue($base); if ((!is_numeric($base)) || (!is_numeric($number))) return PHPExcel_Calculation_Functions::VALUE(); if (($base <= 0) || ($number <= 0)) return PHPExcel_Calculation_Functions::NaN(); return log($number, $base); } // function LOG_BASE() /** * MDETERM * * Returns the matrix determinant of an array. * * Excel Function: * MDETERM(array) * * @access public * @category Mathematical and Trigonometric Functions * @param array $matrixValues A matrix of values * @return float */ public static function MDETERM($matrixValues) { $matrixData = array(); if (!is_array($matrixValues)) { $matrixValues = array(array($matrixValues)); } $row = $maxColumn = 0; foreach($matrixValues as $matrixRow) { if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); } $column = 0; foreach($matrixRow as $matrixCell) { if ((is_string($matrixCell)) || ($matrixCell === null)) { return PHPExcel_Calculation_Functions::VALUE(); } $matrixData[$column][$row] = $matrixCell; ++$column; } if ($column > $maxColumn) { $maxColumn = $column; } ++$row; } if ($row != $maxColumn) { return PHPExcel_Calculation_Functions::VALUE(); } try { $matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData); return $matrix->det(); } catch (PHPExcel_Exception $ex) { return PHPExcel_Calculation_Functions::VALUE(); } } // function MDETERM() /** * MINVERSE * * Returns the inverse matrix for the matrix stored in an array. * * Excel Function: * MINVERSE(array) * * @access public * @category Mathematical and Trigonometric Functions * @param array $matrixValues A matrix of values * @return array */ public static function MINVERSE($matrixValues) { $matrixData = array(); if (!is_array($matrixValues)) { $matrixValues = array(array($matrixValues)); } $row = $maxColumn = 0; foreach($matrixValues as $matrixRow) { if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); } $column = 0; foreach($matrixRow as $matrixCell) { if ((is_string($matrixCell)) || ($matrixCell === null)) { return PHPExcel_Calculation_Functions::VALUE(); } $matrixData[$column][$row] = $matrixCell; ++$column; } if ($column > $maxColumn) { $maxColumn = $column; } ++$row; } if ($row != $maxColumn) { return PHPExcel_Calculation_Functions::VALUE(); } try { $matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData); return $matrix->inverse()->getArray(); } catch (PHPExcel_Exception $ex) { return PHPExcel_Calculation_Functions::VALUE(); } } // function MINVERSE() /** * MMULT * * @param array $matrixData1 A matrix of values * @param array $matrixData2 A matrix of values * @return array */ public static function MMULT($matrixData1,$matrixData2) { $matrixAData = $matrixBData = array(); if (!is_array($matrixData1)) { $matrixData1 = array(array($matrixData1)); } if (!is_array($matrixData2)) { $matrixData2 = array(array($matrixData2)); } $rowA = 0; foreach($matrixData1 as $matrixRow) { if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); } $columnA = 0; foreach($matrixRow as $matrixCell) { if ((is_string($matrixCell)) || ($matrixCell === null)) { return PHPExcel_Calculation_Functions::VALUE(); } $matrixAData[$rowA][$columnA] = $matrixCell; ++$columnA; } ++$rowA; } try { $matrixA = new PHPExcel_Shared_JAMA_Matrix($matrixAData); $rowB = 0; foreach($matrixData2 as $matrixRow) { if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); } $columnB = 0; foreach($matrixRow as $matrixCell) { if ((is_string($matrixCell)) || ($matrixCell === null)) { return PHPExcel_Calculation_Functions::VALUE(); } $matrixBData[$rowB][$columnB] = $matrixCell; ++$columnB; } ++$rowB; } $matrixB = new PHPExcel_Shared_JAMA_Matrix($matrixBData); if (($rowA != $columnB) || ($rowB != $columnA)) { return PHPExcel_Calculation_Functions::VALUE(); } return $matrixA->times($matrixB)->getArray(); } catch (PHPExcel_Exception $ex) { return PHPExcel_Calculation_Functions::VALUE(); } } // function MMULT() /** * MOD * * @param int $a Dividend * @param int $b Divisor * @return int Remainder */ public static function MOD($a = 1, $b = 1) { $a = PHPExcel_Calculation_Functions::flattenSingleValue($a); $b = PHPExcel_Calculation_Functions::flattenSingleValue($b); if ($b == 0.0) { return PHPExcel_Calculation_Functions::DIV0(); } elseif (($a < 0.0) && ($b > 0.0)) { return $b - fmod(abs($a),$b); } elseif (($a > 0.0) && ($b < 0.0)) { return $b + fmod($a,abs($b)); } return fmod($a,$b); } // function MOD() /** * MROUND * * Rounds a number to the nearest multiple of a specified value * * @param float $number Number to round * @param int $multiple Multiple to which you want to round $number * @return float Rounded Number */ public static function MROUND($number,$multiple) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $multiple = PHPExcel_Calculation_Functions::flattenSingleValue($multiple); if ((is_numeric($number)) && (is_numeric($multiple))) { if ($multiple == 0) { return 0; } if ((self::SIGN($number)) == (self::SIGN($multiple))) { $multiplier = 1 / $multiple; return round($number * $multiplier) / $multiplier; } return PHPExcel_Calculation_Functions::NaN(); } return PHPExcel_Calculation_Functions::VALUE(); } // function MROUND() /** * MULTINOMIAL * * Returns the ratio of the factorial of a sum of values to the product of factorials. * * @param array of mixed Data Series * @return float */ public static function MULTINOMIAL() { $summer = 0; $divisor = 1; // Loop through arguments foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { // Is it a numeric value? if (is_numeric($arg)) { if ($arg < 1) { return PHPExcel_Calculation_Functions::NaN(); } $summer += floor($arg); $divisor *= self::FACT($arg); } else { return PHPExcel_Calculation_Functions::VALUE(); } } // Return if ($summer > 0) { $summer = self::FACT($summer); return $summer / $divisor; } return 0; } // function MULTINOMIAL() /** * ODD * * Returns number rounded up to the nearest odd integer. * * @param float $number Number to round * @return int Rounded Number */ public static function ODD($number) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); if (is_null($number)) { return 1; } elseif (is_bool($number)) { $number = (int) $number; } if (is_numeric($number)) { $significance = self::SIGN($number); if ($significance == 0) { return 1; } $result = self::CEILING($number,$significance); if ($result == self::EVEN($result)) { $result += $significance; } return (int) $result; } return PHPExcel_Calculation_Functions::VALUE(); } // function ODD() /** * POWER * * Computes x raised to the power y. * * @param float $x * @param float $y * @return float */ public static function POWER($x = 0, $y = 2) { $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $y = PHPExcel_Calculation_Functions::flattenSingleValue($y); // Validate parameters if ($x == 0.0 && $y == 0.0) { return PHPExcel_Calculation_Functions::NaN(); } elseif ($x == 0.0 && $y < 0.0) { return PHPExcel_Calculation_Functions::DIV0(); } // Return $result = pow($x, $y); return (!is_nan($result) && !is_infinite($result)) ? $result : PHPExcel_Calculation_Functions::NaN(); } // function POWER() /** * PRODUCT * * PRODUCT returns the product of all the values and cells referenced in the argument list. * * Excel Function: * PRODUCT(value1[,value2[, ...]]) * * @access public * @category Mathematical and Trigonometric Functions * @param mixed $arg,... Data values * @return float */ public static function PRODUCT() { // Return value $returnValue = null; // Loop through arguments foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { // Is it a numeric value? if ((is_numeric($arg)) && (!is_string($arg))) { if (is_null($returnValue)) { $returnValue = $arg; } else { $returnValue *= $arg; } } } // Return if (is_null($returnValue)) { return 0; } return $returnValue; } // function PRODUCT() /** * QUOTIENT * * QUOTIENT function returns the integer portion of a division. Numerator is the divided number * and denominator is the divisor. * * Excel Function: * QUOTIENT(value1[,value2[, ...]]) * * @access public * @category Mathematical and Trigonometric Functions * @param mixed $arg,... Data values * @return float */ public static function QUOTIENT() { // Return value $returnValue = null; // Loop through arguments foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { // Is it a numeric value? if ((is_numeric($arg)) && (!is_string($arg))) { if (is_null($returnValue)) { $returnValue = ($arg == 0) ? 0 : $arg; } else { if (($returnValue == 0) || ($arg == 0)) { $returnValue = 0; } else { $returnValue /= $arg; } } } } // Return return intval($returnValue); } // function QUOTIENT() /** * RAND * * @param int $min Minimal value * @param int $max Maximal value * @return int Random number */ public static function RAND($min = 0, $max = 0) { $min = PHPExcel_Calculation_Functions::flattenSingleValue($min); $max = PHPExcel_Calculation_Functions::flattenSingleValue($max); if ($min == 0 && $max == 0) { return (rand(0,10000000)) / 10000000; } else { return rand($min, $max); } } // function RAND() public static function ROMAN($aValue, $style=0) { $aValue = PHPExcel_Calculation_Functions::flattenSingleValue($aValue); $style = (is_null($style)) ? 0 : (integer) PHPExcel_Calculation_Functions::flattenSingleValue($style); if ((!is_numeric($aValue)) || ($aValue < 0) || ($aValue >= 4000)) { return PHPExcel_Calculation_Functions::VALUE(); } $aValue = (integer) $aValue; if ($aValue == 0) { return ''; } $mill = Array('', 'M', 'MM', 'MMM', 'MMMM', 'MMMMM'); $cent = Array('', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'); $tens = Array('', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'); $ones = Array('', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'); $roman = ''; while ($aValue > 5999) { $roman .= 'M'; $aValue -= 1000; } $m = self::_romanCut($aValue, 1000); $aValue %= 1000; $c = self::_romanCut($aValue, 100); $aValue %= 100; $t = self::_romanCut($aValue, 10); $aValue %= 10; return $roman.$mill[$m].$cent[$c].$tens[$t].$ones[$aValue]; } // function ROMAN() /** * ROUNDUP * * Rounds a number up to a specified number of decimal places * * @param float $number Number to round * @param int $digits Number of digits to which you want to round $number * @return float Rounded Number */ public static function ROUNDUP($number,$digits) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); if ((is_numeric($number)) && (is_numeric($digits))) { $significance = pow(10,(int) $digits); if ($number < 0.0) { return floor($number * $significance) / $significance; } else { return ceil($number * $significance) / $significance; } } return PHPExcel_Calculation_Functions::VALUE(); } // function ROUNDUP() /** * ROUNDDOWN * * Rounds a number down to a specified number of decimal places * * @param float $number Number to round * @param int $digits Number of digits to which you want to round $number * @return float Rounded Number */ public static function ROUNDDOWN($number,$digits) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); if ((is_numeric($number)) && (is_numeric($digits))) { $significance = pow(10,(int) $digits); if ($number < 0.0) { return ceil($number * $significance) / $significance; } else { return floor($number * $significance) / $significance; } } return PHPExcel_Calculation_Functions::VALUE(); } // function ROUNDDOWN() /** * SERIESSUM * * Returns the sum of a power series * * @param float $x Input value to the power series * @param float $n Initial power to which you want to raise $x * @param float $m Step by which to increase $n for each term in the series * @param array of mixed Data Series * @return float */ public static function SERIESSUM() { // Return value $returnValue = 0; // Loop through arguments $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $x = array_shift($aArgs); $n = array_shift($aArgs); $m = array_shift($aArgs); if ((is_numeric($x)) && (is_numeric($n)) && (is_numeric($m))) { // Calculate $i = 0; foreach($aArgs as $arg) { // Is it a numeric value? if ((is_numeric($arg)) && (!is_string($arg))) { $returnValue += $arg * pow($x,$n + ($m * $i++)); } else { return PHPExcel_Calculation_Functions::VALUE(); } } // Return return $returnValue; } return PHPExcel_Calculation_Functions::VALUE(); } // function SERIESSUM() /** * SIGN * * Determines the sign of a number. Returns 1 if the number is positive, zero (0) * if the number is 0, and -1 if the number is negative. * * @param float $number Number to round * @return int sign value */ public static function SIGN($number) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); if (is_bool($number)) return (int) $number; if (is_numeric($number)) { if ($number == 0.0) { return 0; } return $number / abs($number); } return PHPExcel_Calculation_Functions::VALUE(); } // function SIGN() /** * SQRTPI * * Returns the square root of (number * pi). * * @param float $number Number * @return float Square Root of Number * Pi */ public static function SQRTPI($number) { $number = PHPExcel_Calculation_Functions::flattenSingleValue($number); if (is_numeric($number)) { if ($number < 0) { return PHPExcel_Calculation_Functions::NaN(); } return sqrt($number * M_PI) ; } return PHPExcel_Calculation_Functions::VALUE(); } // function SQRTPI() /** * SUBTOTAL * * Returns a subtotal in a list or database. * * @param int the number 1 to 11 that specifies which function to * use in calculating subtotals within a list. * @param array of mixed Data Series * @return float */ public static function SUBTOTAL() { $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); // Calculate $subtotal = array_shift($aArgs); if ((is_numeric($subtotal)) && (!is_string($subtotal))) { switch($subtotal) { case 1 : return PHPExcel_Calculation_Statistical::AVERAGE($aArgs); break; case 2 : return PHPExcel_Calculation_Statistical::COUNT($aArgs); break; case 3 : return PHPExcel_Calculation_Statistical::COUNTA($aArgs); break; case 4 : return PHPExcel_Calculation_Statistical::MAX($aArgs); break; case 5 : return PHPExcel_Calculation_Statistical::MIN($aArgs); break; case 6 : return self::PRODUCT($aArgs); break; case 7 : return PHPExcel_Calculation_Statistical::STDEV($aArgs); break; case 8 : return PHPExcel_Calculation_Statistical::STDEVP($aArgs); break; case 9 : return self::SUM($aArgs); break; case 10 : return PHPExcel_Calculation_Statistical::VARFunc($aArgs); break; case 11 : return PHPExcel_Calculation_Statistical::VARP($aArgs); break; } } return PHPExcel_Calculation_Functions::VALUE(); } // function SUBTOTAL() /** * SUM * * SUM computes the sum of all the values and cells referenced in the argument list. * * Excel Function: * SUM(value1[,value2[, ...]]) * * @access public * @category Mathematical and Trigonometric Functions * @param mixed $arg,... Data values * @return float */ public static function SUM() { // Return value $returnValue = 0; // Loop through the arguments foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { // Is it a numeric value? if ((is_numeric($arg)) && (!is_string($arg))) { $returnValue += $arg; } } // Return return $returnValue; } // function SUM() /** * SUMIF * * Counts the number of cells that contain numbers within the list of arguments * * Excel Function: * SUMIF(value1[,value2[, ...]],condition) * * @access public * @category Mathematical and Trigonometric Functions * @param mixed $arg,... Data values * @param string $condition The criteria that defines which cells will be summed. * @return float */ public static function SUMIF($aArgs,$condition,$sumArgs = array()) { // Return value $returnValue = 0; $aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs); $sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs); if (empty($sumArgs)) { $sumArgs = $aArgs; } $condition = PHPExcel_Calculation_Functions::_ifCondition($condition); // Loop through arguments foreach ($aArgs as $key => $arg) { if (!is_numeric($arg)) { $arg = str_replace('"', '""', $arg); $arg = PHPExcel_Calculation::_wrapResult(strtoupper($arg)); } $testCondition = '='.$arg.$condition; if (PHPExcel_Calculation::getInstance()->_calculateFormulaValue($testCondition)) { // Is it a value within our criteria $returnValue += $sumArgs[$key]; } } // Return return $returnValue; } // function SUMIF() /** * SUMPRODUCT * * Excel Function: * SUMPRODUCT(value1[,value2[, ...]]) * * @access public * @category Mathematical and Trigonometric Functions * @param mixed $arg,... Data values * @return float */ public static function SUMPRODUCT() { $arrayList = func_get_args(); $wrkArray = PHPExcel_Calculation_Functions::flattenArray(array_shift($arrayList)); $wrkCellCount = count($wrkArray); for ($i=0; $i< $wrkCellCount; ++$i) { if ((!is_numeric($wrkArray[$i])) || (is_string($wrkArray[$i]))) { $wrkArray[$i] = 0; } } foreach($arrayList as $matrixData) { $array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData); $count = count($array2); if ($wrkCellCount != $count) { return PHPExcel_Calculation_Functions::VALUE(); } foreach ($array2 as $i => $val) { if ((!is_numeric($val)) || (is_string($val))) { $val = 0; } $wrkArray[$i] *= $val; } } return array_sum($wrkArray); } // function SUMPRODUCT() /** * SUMSQ * * SUMSQ returns the sum of the squares of the arguments * * Excel Function: * SUMSQ(value1[,value2[, ...]]) * * @access public * @category Mathematical and Trigonometric Functions * @param mixed $arg,... Data values * @return float */ public static function SUMSQ() { // Return value $returnValue = 0; // Loop through arguments foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { // Is it a numeric value? if ((is_numeric($arg)) && (!is_string($arg))) { $returnValue += ($arg * $arg); } } // Return return $returnValue; } // function SUMSQ() /** * SUMX2MY2 * * @param mixed[] $matrixData1 Matrix #1 * @param mixed[] $matrixData2 Matrix #2 * @return float */ public static function SUMX2MY2($matrixData1,$matrixData2) { $array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1); $array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2); $count1 = count($array1); $count2 = count($array2); if ($count1 < $count2) { $count = $count1; } else { $count = $count2; } $result = 0; for ($i = 0; $i < $count; ++$i) { if (((is_numeric($array1[$i])) && (!is_string($array1[$i]))) && ((is_numeric($array2[$i])) && (!is_string($array2[$i])))) { $result += ($array1[$i] * $array1[$i]) - ($array2[$i] * $array2[$i]); } } return $result; } // function SUMX2MY2() /** * SUMX2PY2 * * @param mixed[] $matrixData1 Matrix #1 * @param mixed[] $matrixData2 Matrix #2 * @return float */ public static function SUMX2PY2($matrixData1,$matrixData2) { $array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1); $array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2); $count1 = count($array1); $count2 = count($array2); if ($count1 < $count2) { $count = $count1; } else { $count = $count2; } $result = 0; for ($i = 0; $i < $count; ++$i) { if (((is_numeric($array1[$i])) && (!is_string($array1[$i]))) && ((is_numeric($array2[$i])) && (!is_string($array2[$i])))) { $result += ($array1[$i] * $array1[$i]) + ($array2[$i] * $array2[$i]); } } return $result; } // function SUMX2PY2() /** * SUMXMY2 * * @param mixed[] $matrixData1 Matrix #1 * @param mixed[] $matrixData2 Matrix #2 * @return float */ public static function SUMXMY2($matrixData1,$matrixData2) { $array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1); $array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2); $count1 = count($array1); $count2 = count($array2); if ($count1 < $count2) { $count = $count1; } else { $count = $count2; } $result = 0; for ($i = 0; $i < $count; ++$i) { if (((is_numeric($array1[$i])) && (!is_string($array1[$i]))) && ((is_numeric($array2[$i])) && (!is_string($array2[$i])))) { $result += ($array1[$i] - $array2[$i]) * ($array1[$i] - $array2[$i]); } } return $result; } // function SUMXMY2() /** * TRUNC * * Truncates value to the number of fractional digits by number_digits. * * @param float $value * @param int $digits * @return float Truncated value */ public static function TRUNC($value = 0, $digits = 0) { $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); // Validate parameters if ((!is_numeric($value)) || (!is_numeric($digits))) return PHPExcel_Calculation_Functions::VALUE(); $digits = floor($digits); // Truncate $adjust = pow(10, $digits); if (($digits > 0) && (rtrim(intval((abs($value) - abs(intval($value))) * $adjust),'0') < $adjust/10)) return $value; return (intval($value * $adjust)) / $adjust; } // function TRUNC() } // class PHPExcel_Calculation_MathTrig PK ! zΧm m ! PHPExcel/Calculation/Database.phpnu [ $criteriaName) { $testCondition = array(); $testConditionCount = 0; foreach($criteria as $row => $criterion) { if ($criterion[$key] > '') { $testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::_ifCondition($criterion[$key]); $testConditionCount++; } } if ($testConditionCount > 1) { $testConditions[] = 'OR('.implode(',',$testCondition).')'; $testConditionsCount++; } elseif($testConditionCount == 1) { $testConditions[] = $testCondition[0]; $testConditionsCount++; } } if ($testConditionsCount > 1) { $testConditionSet = 'AND('.implode(',',$testConditions).')'; } elseif($testConditionsCount == 1) { $testConditionSet = $testConditions[0]; } // Loop through each row of the database foreach($database as $dataRow => $dataValues) { // Substitute actual values from the database row for our [:placeholders] $testConditionList = $testConditionSet; foreach($criteriaNames as $key => $criteriaName) { $k = array_search($criteriaName,$fieldNames); if (isset($dataValues[$k])) { $dataValue = $dataValues[$k]; $dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::_wrapResult(strtoupper($dataValue)) : $dataValue; $testConditionList = str_replace('[:'.$criteriaName.']',$dataValue,$testConditionList); } } // evaluate the criteria against the row data $result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList); // If the row failed to meet the criteria, remove it from the database if (!$result) { unset($database[$dataRow]); } } return $database; } /** * DAVERAGE * * Averages the values in a column of a list or database that match conditions you specify. * * Excel Function: * DAVERAGE(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return float * */ public static function DAVERAGE($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_Statistical::AVERAGE($colData); } // function DAVERAGE() /** * DCOUNT * * Counts the cells that contain numbers in a column of a list or database that match conditions * that you specify. * * Excel Function: * DCOUNT(database,[field],criteria) * * Excel Function: * DAVERAGE(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return integer * * @TODO The field argument is optional. If field is omitted, DCOUNT counts all records in the * database that match the criteria. * */ public static function DCOUNT($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_Statistical::COUNT($colData); } // function DCOUNT() /** * DCOUNTA * * Counts the nonblank cells in a column of a list or database that match conditions that you specify. * * Excel Function: * DCOUNTA(database,[field],criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return integer * * @TODO The field argument is optional. If field is omitted, DCOUNTA counts all records in the * database that match the criteria. * */ public static function DCOUNTA($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_Statistical::COUNTA($colData); } // function DCOUNTA() /** * DGET * * Extracts a single value from a column of a list or database that matches conditions that you * specify. * * Excel Function: * DGET(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return mixed * */ public static function DGET($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return if (count($colData) > 1) { return PHPExcel_Calculation_Functions::NaN(); } return $colData[0]; } // function DGET() /** * DMAX * * Returns the largest number in a column of a list or database that matches conditions you that * specify. * * Excel Function: * DMAX(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return float * */ public static function DMAX($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_Statistical::MAX($colData); } // function DMAX() /** * DMIN * * Returns the smallest number in a column of a list or database that matches conditions you that * specify. * * Excel Function: * DMIN(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return float * */ public static function DMIN($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_Statistical::MIN($colData); } // function DMIN() /** * DPRODUCT * * Multiplies the values in a column of a list or database that match conditions that you specify. * * Excel Function: * DPRODUCT(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return float * */ public static function DPRODUCT($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_MathTrig::PRODUCT($colData); } // function DPRODUCT() /** * DSTDEV * * Estimates the standard deviation of a population based on a sample by using the numbers in a * column of a list or database that match conditions that you specify. * * Excel Function: * DSTDEV(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return float * */ public static function DSTDEV($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_Statistical::STDEV($colData); } // function DSTDEV() /** * DSTDEVP * * Calculates the standard deviation of a population based on the entire population by using the * numbers in a column of a list or database that match conditions that you specify. * * Excel Function: * DSTDEVP(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return float * */ public static function DSTDEVP($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_Statistical::STDEVP($colData); } // function DSTDEVP() /** * DSUM * * Adds the numbers in a column of a list or database that match conditions that you specify. * * Excel Function: * DSUM(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return float * */ public static function DSUM($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_MathTrig::SUM($colData); } // function DSUM() /** * DVAR * * Estimates the variance of a population based on a sample by using the numbers in a column * of a list or database that match conditions that you specify. * * Excel Function: * DVAR(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return float * */ public static function DVAR($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_Statistical::VARFunc($colData); } // function DVAR() /** * DVARP * * Calculates the variance of a population based on the entire population by using the numbers * in a column of a list or database that match conditions that you specify. * * Excel Function: * DVARP(database,field,criteria) * * @access public * @category Database Functions * @param mixed[] $database The range of cells that makes up the list or database. * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param string|integer $field Indicates which column is used in the function. Enter the * column label enclosed between double quotation marks, such as * "Age" or "Yield," or a number (without quotation marks) that * represents the position of the column within the list: 1 for * the first column, 2 for the second column, and so on. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return float * */ public static function DVARP($database,$field,$criteria) { $field = self::__fieldExtract($database,$field); if (is_null($field)) { return NULL; } // reduce the database to a set of rows that match all the criteria $database = self::__filter($database,$criteria); // extract an array of values for the requested column $colData = array(); foreach($database as $row) { $colData[] = $row[$field]; } // Return return PHPExcel_Calculation_Statistical::VARP($colData); } // function DVARP() } // class PHPExcel_Calculation_Database PK ! ; 'Ƨ $ PHPExcel/Calculation/Statistical.phpnu [ $value) { if ((is_bool($value)) || (is_string($value)) || (is_null($value))) { unset($array1[$key]); unset($array2[$key]); } } foreach($array2 as $key => $value) { if ((is_bool($value)) || (is_string($value)) || (is_null($value))) { unset($array1[$key]); unset($array2[$key]); } } $array1 = array_merge($array1); $array2 = array_merge($array2); return True; } // function _checkTrendArrays() /** * Beta function. * * @author Jaco van Kooten * * @param p require p>0 * @param q require q>0 * @return 0 if p<=0, q<=0 or p+q>2.55E305 to avoid errors and over/underflow */ private static function _beta($p, $q) { if ($p <= 0.0 || $q <= 0.0 || ($p + $q) > LOG_GAMMA_X_MAX_VALUE) { return 0.0; } else { return exp(self::_logBeta($p, $q)); } } // function _beta() /** * Incomplete beta function * * @author Jaco van Kooten * @author Paul Meagher * * The computation is based on formulas from Numerical Recipes, Chapter 6.4 (W.H. Press et al, 1992). * @param x require 0<=x<=1 * @param p require p>0 * @param q require q>0 * @return 0 if x<0, p<=0, q<=0 or p+q>2.55E305 and 1 if x>1 to avoid errors and over/underflow */ private static function _incompleteBeta($x, $p, $q) { if ($x <= 0.0) { return 0.0; } elseif ($x >= 1.0) { return 1.0; } elseif (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > LOG_GAMMA_X_MAX_VALUE)) { return 0.0; } $beta_gam = exp((0 - self::_logBeta($p, $q)) + $p * log($x) + $q * log(1.0 - $x)); if ($x < ($p + 1.0) / ($p + $q + 2.0)) { return $beta_gam * self::_betaFraction($x, $p, $q) / $p; } else { return 1.0 - ($beta_gam * self::_betaFraction(1 - $x, $q, $p) / $q); } } // function _incompleteBeta() // Function cache for _logBeta function private static $_logBetaCache_p = 0.0; private static $_logBetaCache_q = 0.0; private static $_logBetaCache_result = 0.0; /** * The natural logarithm of the beta function. * * @param p require p>0 * @param q require q>0 * @return 0 if p<=0, q<=0 or p+q>2.55E305 to avoid errors and over/underflow * @author Jaco van Kooten */ private static function _logBeta($p, $q) { if ($p != self::$_logBetaCache_p || $q != self::$_logBetaCache_q) { self::$_logBetaCache_p = $p; self::$_logBetaCache_q = $q; if (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > LOG_GAMMA_X_MAX_VALUE)) { self::$_logBetaCache_result = 0.0; } else { self::$_logBetaCache_result = self::_logGamma($p) + self::_logGamma($q) - self::_logGamma($p + $q); } } return self::$_logBetaCache_result; } // function _logBeta() /** * Evaluates of continued fraction part of incomplete beta function. * Based on an idea from Numerical Recipes (W.H. Press et al, 1992). * @author Jaco van Kooten */ private static function _betaFraction($x, $p, $q) { $c = 1.0; $sum_pq = $p + $q; $p_plus = $p + 1.0; $p_minus = $p - 1.0; $h = 1.0 - $sum_pq * $x / $p_plus; if (abs($h) < XMININ) { $h = XMININ; } $h = 1.0 / $h; $frac = $h; $m = 1; $delta = 0.0; while ($m <= MAX_ITERATIONS && abs($delta-1.0) > PRECISION ) { $m2 = 2 * $m; // even index for d $d = $m * ($q - $m) * $x / ( ($p_minus + $m2) * ($p + $m2)); $h = 1.0 + $d * $h; if (abs($h) < XMININ) { $h = XMININ; } $h = 1.0 / $h; $c = 1.0 + $d / $c; if (abs($c) < XMININ) { $c = XMININ; } $frac *= $h * $c; // odd index for d $d = -($p + $m) * ($sum_pq + $m) * $x / (($p + $m2) * ($p_plus + $m2)); $h = 1.0 + $d * $h; if (abs($h) < XMININ) { $h = XMININ; } $h = 1.0 / $h; $c = 1.0 + $d / $c; if (abs($c) < XMININ) { $c = XMININ; } $delta = $h * $c; $frac *= $delta; ++$m; } return $frac; } // function _betaFraction() /** * logGamma function * * @version 1.1 * @author Jaco van Kooten * * Original author was Jaco van Kooten. Ported to PHP by Paul Meagher. * * The natural logarithm of the gamma function.* References: *
* From the original documentation: *
** This routine calculates the LOG(GAMMA) function for a positive real argument X. * Computation is based on an algorithm outlined in references 1 and 2. * The program uses rational functions that theoretically approximate LOG(GAMMA) * to at least 18 significant decimal digits. The approximation for X > 12 is from * reference 3, while approximations for X < 12.0 are similar to those in reference * 1, but are unpublished. The accuracy achieved depends on the arithmetic system, * the compiler, the intrinsic functions, and proper selection of the * machine-dependent constants. *
*
* Error returns:
* The program returns the value XINF for X .LE. 0.0 or when overflow would occur.
* The computation is believed to be free of underflow and overflow.
*