More namespacing work and soem initial rework for unit tests to handle new folder structure

This commit is contained in:
MarkBaker 2015-05-26 09:37:07 +01:00
parent 550907fc77
commit 538fe93105
51 changed files with 1153 additions and 1208 deletions

View File

@ -530,16 +530,16 @@ class DateTime
$testVal3 = strftime('%Y'); $testVal3 = strftime('%Y');
} }
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$PHPDateArray = date_parse($testVal1.'-'.$testVal2.'-'.$testVal3); $PHPDateArray = date_parse($testVal1.'-'.$testVal2.'-'.$testVal3);
if (($PHPDateArray === false) || ($PHPDateArray['error_count'] > 0)) { if (($PHPDateArray === false) || ($PHPDateArray['error_count'] > 0)) {
$PHPDateArray = date_parse($testVal2.'-'.$testVal1.'-'.$testVal3); $PHPDateArray = date_parse($testVal2.'-'.$testVal1.'-'.$testVal3);
if (($PHPDateArray === false) || ($PHPDateArray['error_count'] > 0)) { if (($PHPDateArray === false) || ($PHPDateArray['error_count'] > 0)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
} }
@ -550,7 +550,7 @@ class DateTime
$PHPDateArray['year'] = strftime('%Y'); $PHPDateArray['year'] = strftime('%Y');
} }
if ($PHPDateArray['year'] < 1900) { if ($PHPDateArray['year'] < 1900) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if ($PHPDateArray['month'] == '') { if ($PHPDateArray['month'] == '') {
$PHPDateArray['month'] = strftime('%m'); $PHPDateArray['month'] = strftime('%m');
@ -569,16 +569,16 @@ class DateTime
) )
); );
switch (PHPExcel_Calculation_Functions::getReturnDateType()) { switch (Functions::getReturnDateType()) {
case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL: case Functions::RETURNDATE_EXCEL:
return (float) $excelDateValue; return (float) $excelDateValue;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC: case Functions::RETURNDATE_PHP_NUMERIC:
return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue); return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT: case Functions::RETURNDATE_PHP_OBJECT:
return new DateTime($PHPDateArray['year'].'-'.$PHPDateArray['month'].'-'.$PHPDateArray['day'].' 00:00:00'); return new DateTime($PHPDateArray['year'].'-'.$PHPDateArray['month'].'-'.$PHPDateArray['day'].' 00:00:00');
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -606,12 +606,12 @@ class DateTime
*/ */
public static function TIMEVALUE($timeValue) public static function TIMEVALUE($timeValue)
{ {
$timeValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($timeValue), '"'); $timeValue = trim(Functions::flattenSingleValue($timeValue), '"');
$timeValue = str_replace(array('/', '.'), array('-', '-'), $timeValue); $timeValue = str_replace(array('/', '.'), array('-', '-'), $timeValue);
$PHPDateArray = date_parse($timeValue); $PHPDateArray = date_parse($timeValue);
if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) { if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel( $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel(
$PHPDateArray['year'], $PHPDateArray['year'],
$PHPDateArray['month'], $PHPDateArray['month'],
@ -624,16 +624,16 @@ class DateTime
$excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1; $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1;
} }
switch (PHPExcel_Calculation_Functions::getReturnDateType()) { switch (Functions::getReturnDateType()) {
case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL: case Functions::RETURNDATE_EXCEL:
return (float) $excelDateValue; return (float) $excelDateValue;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC: case Functions::RETURNDATE_PHP_NUMERIC:
return (integer) $phpDateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue+25569) - 3600; return (integer) $phpDateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue+25569) - 3600;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT: case Functions::RETURNDATE_PHP_OBJECT:
return new DateTime('1900-01-01 '.$PHPDateArray['hour'].':'.$PHPDateArray['minute'].':'.$PHPDateArray['second']); return new DateTime('1900-01-01 '.$PHPDateArray['hour'].':'.$PHPDateArray['minute'].':'.$PHPDateArray['second']);
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -649,20 +649,20 @@ class DateTime
*/ */
public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D') public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D')
{ {
$startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $startDate = Functions::flattenSingleValue($startDate);
$endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate); $endDate = Functions::flattenSingleValue($endDate);
$unit = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($unit)); $unit = strtoupper(Functions::flattenSingleValue($unit));
if (is_string($startDate = self::getDateValue($startDate))) { if (is_string($startDate = self::getDateValue($startDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (is_string($endDate = self::getDateValue($endDate))) { if (is_string($endDate = self::getDateValue($endDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
// Validate parameters // Validate parameters
if ($startDate >= $endDate) { if ($startDate >= $endDate) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
// Execute function // Execute function
@ -678,7 +678,7 @@ class DateTime
$endMonths = $PHPEndDateObject->format('n'); $endMonths = $PHPEndDateObject->format('n');
$endYears = $PHPEndDateObject->format('Y'); $endYears = $PHPEndDateObject->format('Y');
$retVal = PHPExcel_Calculation_Functions::NaN(); $retVal = Functions::NaN();
switch ($unit) { switch ($unit) {
case 'D': case 'D':
$retVal = intval($difference); $retVal = intval($difference);
@ -735,7 +735,7 @@ class DateTime
} }
break; break;
default: default:
$retVal = PHPExcel_Calculation_Functions::NaN(); $retVal = Functions::NaN();
} }
return $retVal; return $retVal;
} }
@ -772,18 +772,18 @@ class DateTime
*/ */
public static function DAYS360($startDate = 0, $endDate = 0, $method = false) public static function DAYS360($startDate = 0, $endDate = 0, $method = false)
{ {
$startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $startDate = Functions::flattenSingleValue($startDate);
$endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate); $endDate = Functions::flattenSingleValue($endDate);
if (is_string($startDate = self::getDateValue($startDate))) { if (is_string($startDate = self::getDateValue($startDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (is_string($endDate = self::getDateValue($endDate))) { if (is_string($endDate = self::getDateValue($endDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (!is_bool($method)) { if (!is_bool($method)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
// Execute function // Execute function
@ -828,15 +828,15 @@ class DateTime
*/ */
public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0) public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
{ {
$startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $startDate = Functions::flattenSingleValue($startDate);
$endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate); $endDate = Functions::flattenSingleValue($endDate);
$method = PHPExcel_Calculation_Functions::flattenSingleValue($method); $method = Functions::flattenSingleValue($method);
if (is_string($startDate = self::getDateValue($startDate))) { if (is_string($startDate = self::getDateValue($startDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (is_string($endDate = self::getDateValue($endDate))) { if (is_string($endDate = self::getDateValue($endDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (((is_numeric($method)) && (!is_string($method))) || ($method == '')) { if (((is_numeric($method)) && (!is_string($method))) || ($method == '')) {
@ -895,7 +895,7 @@ class DateTime
return self::DAYS360($startDate, $endDate, true) / 360; return self::DAYS360($startDate, $endDate, true) / 360;
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -925,20 +925,20 @@ class DateTime
public static function NETWORKDAYS($startDate, $endDate) public static function NETWORKDAYS($startDate, $endDate)
{ {
// Retrieve the mandatory start and end date that are referenced in the function definition // Retrieve the mandatory start and end date that are referenced in the function definition
$startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $startDate = Functions::flattenSingleValue($startDate);
$endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate); $endDate = Functions::flattenSingleValue($endDate);
// Flush the mandatory start and end date that are referenced in the function definition, and get the optional days // 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()); $dateArgs = Functions::flattenArray(func_get_args());
array_shift($dateArgs); array_shift($dateArgs);
array_shift($dateArgs); array_shift($dateArgs);
// Validate the start and end dates // Validate the start and end dates
if (is_string($startDate = $sDate = self::getDateValue($startDate))) { if (is_string($startDate = $sDate = self::getDateValue($startDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$startDate = (float) floor($startDate); $startDate = (float) floor($startDate);
if (is_string($endDate = $eDate = self::getDateValue($endDate))) { if (is_string($endDate = $eDate = self::getDateValue($endDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$endDate = (float) floor($endDate); $endDate = (float) floor($endDate);
@ -967,7 +967,7 @@ class DateTime
$holidayCountedArray = array(); $holidayCountedArray = array();
foreach ($dateArgs as $holidayDate) { foreach ($dateArgs as $holidayDate) {
if (is_string($holidayDate = self::getDateValue($holidayDate))) { if (is_string($holidayDate = self::getDateValue($holidayDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) { if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
if ((self::DAYOFWEEK($holidayDate, 2) < 6) && (!in_array($holidayDate, $holidayCountedArray))) { if ((self::DAYOFWEEK($holidayDate, 2) < 6) && (!in_array($holidayDate, $holidayCountedArray))) {
@ -1012,15 +1012,15 @@ class DateTime
public static function WORKDAY($startDate, $endDays) public static function WORKDAY($startDate, $endDays)
{ {
// Retrieve the mandatory start date and days that are referenced in the function definition // Retrieve the mandatory start date and days that are referenced in the function definition
$startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); $startDate = Functions::flattenSingleValue($startDate);
$endDays = PHPExcel_Calculation_Functions::flattenSingleValue($endDays); $endDays = Functions::flattenSingleValue($endDays);
// Flush the mandatory start date and days that are referenced in the function definition, and get the optional days // 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()); $dateArgs = Functions::flattenArray(func_get_args());
array_shift($dateArgs); array_shift($dateArgs);
array_shift($dateArgs); array_shift($dateArgs);
if ((is_string($startDate = self::getDateValue($startDate))) || (!is_numeric($endDays))) { if ((is_string($startDate = self::getDateValue($startDate))) || (!is_numeric($endDays))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$startDate = (float) floor($startDate); $startDate = (float) floor($startDate);
$endDays = (int) floor($endDays); $endDays = (int) floor($endDays);
@ -1054,7 +1054,7 @@ class DateTime
foreach ($dateArgs as $holidayDate) { foreach ($dateArgs as $holidayDate) {
if (($holidayDate !== null) && (trim($holidayDate) > '')) { if (($holidayDate !== null) && (trim($holidayDate) > '')) {
if (is_string($holidayDate = self::getDateValue($holidayDate))) { if (is_string($holidayDate = self::getDateValue($holidayDate))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (self::DAYOFWEEK($holidayDate, 3) < 5) { if (self::DAYOFWEEK($holidayDate, 3) < 5) {
$holidayDates[] = $holidayDate; $holidayDates[] = $holidayDate;
@ -1090,12 +1090,12 @@ class DateTime
} }
} }
switch (PHPExcel_Calculation_Functions::getReturnDateType()) { switch (Functions::getReturnDateType()) {
case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL: case Functions::RETURNDATE_EXCEL:
return (float) $endDate; return (float) $endDate;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC: case Functions::RETURNDATE_PHP_NUMERIC:
return (integer) PHPExcel_Shared_Date::ExcelToPHP($endDate); return (integer) PHPExcel_Shared_Date::ExcelToPHP($endDate);
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT: case Functions::RETURNDATE_PHP_OBJECT:
return PHPExcel_Shared_Date::ExcelToPHPObject($endDate); return PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
} }
} }
@ -1116,16 +1116,16 @@ class DateTime
*/ */
public static function DAYOFMONTH($dateValue = 1) public static function DAYOFMONTH($dateValue = 1)
{ {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $dateValue = Functions::flattenSingleValue($dateValue);
if ($dateValue === null) { if ($dateValue === null) {
$dateValue = 1; $dateValue = 1;
} elseif (is_string($dateValue = self::getDateValue($dateValue))) { } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif ($dateValue == 0.0) { } elseif ($dateValue == 0.0) {
return 0; return 0;
} elseif ($dateValue < 0.0) { } elseif ($dateValue < 0.0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
// Execute function // Execute function
@ -1154,22 +1154,22 @@ class DateTime
*/ */
public static function DAYOFWEEK($dateValue = 1, $style = 1) public static function DAYOFWEEK($dateValue = 1, $style = 1)
{ {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $dateValue = Functions::flattenSingleValue($dateValue);
$style = PHPExcel_Calculation_Functions::flattenSingleValue($style); $style = Functions::flattenSingleValue($style);
if (!is_numeric($style)) { if (!is_numeric($style)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif (($style < 1) || ($style > 3)) { } elseif (($style < 1) || ($style > 3)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$style = floor($style); $style = floor($style);
if ($dateValue === null) { if ($dateValue === null) {
$dateValue = 1; $dateValue = 1;
} elseif (is_string($dateValue = self::getDateValue($dateValue))) { } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif ($dateValue < 0.0) { } elseif ($dateValue < 0.0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
// Execute function // Execute function
@ -1194,7 +1194,7 @@ class DateTime
--$DoW; --$DoW;
break; break;
} }
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_EXCEL) {
// Test for Excel's 1900 leap year, and introduce the error as required // Test for Excel's 1900 leap year, and introduce the error as required
if (($PHPDateObject->format('Y') == 1900) && ($PHPDateObject->format('n') <= 2)) { if (($PHPDateObject->format('Y') == 1900) && ($PHPDateObject->format('n') <= 2)) {
--$DoW; --$DoW;
@ -1230,22 +1230,22 @@ class DateTime
*/ */
public static function WEEKOFYEAR($dateValue = 1, $method = 1) public static function WEEKOFYEAR($dateValue = 1, $method = 1)
{ {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $dateValue = Functions::flattenSingleValue($dateValue);
$method = PHPExcel_Calculation_Functions::flattenSingleValue($method); $method = Functions::flattenSingleValue($method);
if (!is_numeric($method)) { if (!is_numeric($method)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif (($method < 1) || ($method > 2)) { } elseif (($method < 1) || ($method > 2)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$method = floor($method); $method = floor($method);
if ($dateValue === null) { if ($dateValue === null) {
$dateValue = 1; $dateValue = 1;
} elseif (is_string($dateValue = self::getDateValue($dateValue))) { } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif ($dateValue < 0.0) { } elseif ($dateValue < 0.0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
// Execute function // Execute function
@ -1277,14 +1277,14 @@ class DateTime
*/ */
public static function MONTHOFYEAR($dateValue = 1) public static function MONTHOFYEAR($dateValue = 1)
{ {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $dateValue = Functions::flattenSingleValue($dateValue);
if ($dateValue === null) { if ($dateValue === null) {
$dateValue = 1; $dateValue = 1;
} elseif (is_string($dateValue = self::getDateValue($dateValue))) { } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif ($dateValue < 0.0) { } elseif ($dateValue < 0.0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
// Execute function // Execute function
@ -1309,14 +1309,14 @@ class DateTime
*/ */
public static function YEAR($dateValue = 1) public static function YEAR($dateValue = 1)
{ {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $dateValue = Functions::flattenSingleValue($dateValue);
if ($dateValue === null) { if ($dateValue === null) {
$dateValue = 1; $dateValue = 1;
} elseif (is_string($dateValue = self::getDateValue($dateValue))) { } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif ($dateValue < 0.0) { } elseif ($dateValue < 0.0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
// Execute function // Execute function
@ -1341,25 +1341,25 @@ class DateTime
*/ */
public static function HOUROFDAY($timeValue = 0) public static function HOUROFDAY($timeValue = 0)
{ {
$timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue); $timeValue = Functions::flattenSingleValue($timeValue);
if (!is_numeric($timeValue)) { if (!is_numeric($timeValue)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
$testVal = strtok($timeValue, '/-: '); $testVal = strtok($timeValue, '/-: ');
if (strlen($testVal) < strlen($timeValue)) { if (strlen($testVal) < strlen($timeValue)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
$timeValue = self::getTimeValue($timeValue); $timeValue = self::getTimeValue($timeValue);
if (is_string($timeValue)) { if (is_string($timeValue)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
// Execute function // Execute function
if ($timeValue >= 1) { if ($timeValue >= 1) {
$timeValue = fmod($timeValue, 1); $timeValue = fmod($timeValue, 1);
} elseif ($timeValue < 0.0) { } elseif ($timeValue < 0.0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue); $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
@ -1382,25 +1382,25 @@ class DateTime
*/ */
public static function MINUTEOFHOUR($timeValue = 0) public static function MINUTEOFHOUR($timeValue = 0)
{ {
$timeValue = $timeTester = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue); $timeValue = $timeTester = Functions::flattenSingleValue($timeValue);
if (!is_numeric($timeValue)) { if (!is_numeric($timeValue)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
$testVal = strtok($timeValue, '/-: '); $testVal = strtok($timeValue, '/-: ');
if (strlen($testVal) < strlen($timeValue)) { if (strlen($testVal) < strlen($timeValue)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
$timeValue = self::getTimeValue($timeValue); $timeValue = self::getTimeValue($timeValue);
if (is_string($timeValue)) { if (is_string($timeValue)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
// Execute function // Execute function
if ($timeValue >= 1) { if ($timeValue >= 1) {
$timeValue = fmod($timeValue, 1); $timeValue = fmod($timeValue, 1);
} elseif ($timeValue < 0.0) { } elseif ($timeValue < 0.0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue); $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
@ -1423,25 +1423,25 @@ class DateTime
*/ */
public static function SECONDOFMINUTE($timeValue = 0) public static function SECONDOFMINUTE($timeValue = 0)
{ {
$timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue); $timeValue = Functions::flattenSingleValue($timeValue);
if (!is_numeric($timeValue)) { if (!is_numeric($timeValue)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
$testVal = strtok($timeValue, '/-: '); $testVal = strtok($timeValue, '/-: ');
if (strlen($testVal) < strlen($timeValue)) { if (strlen($testVal) < strlen($timeValue)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
$timeValue = self::getTimeValue($timeValue); $timeValue = self::getTimeValue($timeValue);
if (is_string($timeValue)) { if (is_string($timeValue)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
// Execute function // Execute function
if ($timeValue >= 1) { if ($timeValue >= 1) {
$timeValue = fmod($timeValue, 1); $timeValue = fmod($timeValue, 1);
} elseif ($timeValue < 0.0) { } elseif ($timeValue < 0.0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue); $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
@ -1470,27 +1470,27 @@ class DateTime
*/ */
public static function EDATE($dateValue = 1, $adjustmentMonths = 0) public static function EDATE($dateValue = 1, $adjustmentMonths = 0)
{ {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $dateValue = Functions::flattenSingleValue($dateValue);
$adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths); $adjustmentMonths = Functions::flattenSingleValue($adjustmentMonths);
if (!is_numeric($adjustmentMonths)) { if (!is_numeric($adjustmentMonths)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$adjustmentMonths = floor($adjustmentMonths); $adjustmentMonths = floor($adjustmentMonths);
if (is_string($dateValue = self::getDateValue($dateValue))) { if (is_string($dateValue = self::getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
// Execute function // Execute function
$PHPDateObject = self::adjustDateByMonths($dateValue, $adjustmentMonths); $PHPDateObject = self::adjustDateByMonths($dateValue, $adjustmentMonths);
switch (PHPExcel_Calculation_Functions::getReturnDateType()) { switch (Functions::getReturnDateType()) {
case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL: case Functions::RETURNDATE_EXCEL:
return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject); return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC: case Functions::RETURNDATE_PHP_NUMERIC:
return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject)); return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject));
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT: case Functions::RETURNDATE_PHP_OBJECT:
return $PHPDateObject; return $PHPDateObject;
} }
} }
@ -1516,16 +1516,16 @@ class DateTime
*/ */
public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0) public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0)
{ {
$dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue); $dateValue = Functions::flattenSingleValue($dateValue);
$adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths); $adjustmentMonths = Functions::flattenSingleValue($adjustmentMonths);
if (!is_numeric($adjustmentMonths)) { if (!is_numeric($adjustmentMonths)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$adjustmentMonths = floor($adjustmentMonths); $adjustmentMonths = floor($adjustmentMonths);
if (is_string($dateValue = self::getDateValue($dateValue))) { if (is_string($dateValue = self::getDateValue($dateValue))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
// Execute function // Execute function
@ -1534,12 +1534,12 @@ class DateTime
$adjustDaysString = '-' . $adjustDays . ' days'; $adjustDaysString = '-' . $adjustDays . ' days';
$PHPDateObject->modify($adjustDaysString); $PHPDateObject->modify($adjustDaysString);
switch (PHPExcel_Calculation_Functions::getReturnDateType()) { switch (Functions::getReturnDateType()) {
case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL: case Functions::RETURNDATE_EXCEL:
return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject); return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC: case Functions::RETURNDATE_PHP_NUMERIC:
return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject)); return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject));
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT: case Functions::RETURNDATE_PHP_OBJECT:
return $PHPDateObject; return $PHPDateObject;
} }
} }

View File

@ -830,7 +830,7 @@ class Engineering
if (strlen($xVal) <= $places) { if (strlen($xVal) <= $places) {
return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10); return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10);
} else { } else {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
} }
@ -859,17 +859,17 @@ class Engineering
*/ */
public static function BESSELI($x, $ord) public static function BESSELI($x, $ord)
{ {
$x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = (is_null($x)) ? 0.0 : Functions::flattenSingleValue($x);
$ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord); $ord = (is_null($ord)) ? 0.0 : Functions::flattenSingleValue($ord);
if ((is_numeric($x)) && (is_numeric($ord))) { if ((is_numeric($x)) && (is_numeric($ord))) {
$ord = floor($ord); $ord = floor($ord);
if ($ord < 0) { if ($ord < 0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
if (abs($x) <= 30) { if (abs($x) <= 30) {
$fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord); $fResult = $fTerm = pow($x / 2, $ord) / MathTrig::FACT($ord);
$ordK = 1; $ordK = 1;
$fSqrX = ($x * $x) / 4; $fSqrX = ($x * $x) / 4;
do { do {
@ -886,9 +886,9 @@ class Engineering
$fResult = -$fResult; $fResult = -$fResult;
} }
} }
return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult; return (is_nan($fResult)) ? Functions::NaN() : $fResult;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -912,18 +912,18 @@ class Engineering
*/ */
public static function BESSELJ($x, $ord) public static function BESSELJ($x, $ord)
{ {
$x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = (is_null($x)) ? 0.0 : Functions::flattenSingleValue($x);
$ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord); $ord = (is_null($ord)) ? 0.0 : Functions::flattenSingleValue($ord);
if ((is_numeric($x)) && (is_numeric($ord))) { if ((is_numeric($x)) && (is_numeric($ord))) {
$ord = floor($ord); $ord = floor($ord);
if ($ord < 0) { if ($ord < 0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$fResult = 0; $fResult = 0;
if (abs($x) <= 30) { if (abs($x) <= 30) {
$fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord); $fResult = $fTerm = pow($x / 2, $ord) / MathTrig::FACT($ord);
$ordK = 1; $ordK = 1;
$fSqrX = ($x * $x) / -4; $fSqrX = ($x * $x) / -4;
do { do {
@ -941,9 +941,9 @@ class Engineering
$fResult = -$fResult; $fResult = -$fResult;
} }
} }
return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult; return (is_nan($fResult)) ? Functions::NaN() : $fResult;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -1004,12 +1004,12 @@ class Engineering
*/ */
public static function BESSELK($x, $ord) public static function BESSELK($x, $ord)
{ {
$x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = (is_null($x)) ? 0.0 : Functions::flattenSingleValue($x);
$ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord); $ord = (is_null($ord)) ? 0.0 : Functions::flattenSingleValue($ord);
if ((is_numeric($x)) && (is_numeric($ord))) { if ((is_numeric($x)) && (is_numeric($ord))) {
if (($ord < 0) || ($x == 0.0)) { if (($ord < 0) || ($x == 0.0)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
switch (floor($ord)) { switch (floor($ord)) {
@ -1027,9 +1027,9 @@ class Engineering
$fBk = $fBkp; $fBk = $fBkp;
} }
} }
return (is_nan($fBk)) ? PHPExcel_Calculation_Functions::NaN() : $fBk; return (is_nan($fBk)) ? Functions::NaN() : $fBk;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -1088,12 +1088,12 @@ class Engineering
*/ */
public static function BESSELY($x, $ord) public static function BESSELY($x, $ord)
{ {
$x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = (is_null($x)) ? 0.0 : Functions::flattenSingleValue($x);
$ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord); $ord = (is_null($ord)) ? 0.0 : Functions::flattenSingleValue($ord);
if ((is_numeric($x)) && (is_numeric($ord))) { if ((is_numeric($x)) && (is_numeric($ord))) {
if (($ord < 0) || ($x == 0.0)) { if (($ord < 0) || ($x == 0.0)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
switch (floor($ord)) { switch (floor($ord)) {
@ -1111,9 +1111,9 @@ class Engineering
$fBy = $fByp; $fBy = $fByp;
} }
} }
return (is_nan($fBy)) ? PHPExcel_Calculation_Functions::NaN() : $fBy; return (is_nan($fBy)) ? Functions::NaN() : $fBy;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -1137,24 +1137,24 @@ class Engineering
*/ */
public static function BINTODEC($x) public static function BINTODEC($x)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
if (is_bool($x)) { if (is_bool($x)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$x = (int) $x; $x = (int) $x;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
$x = floor($x); $x = floor($x);
} }
$x = (string) $x; $x = (string) $x;
if (strlen($x) > preg_match_all('/[01]/', $x, $out)) { if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
if (strlen($x) > 10) { if (strlen($x) > 10) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} elseif (strlen($x) == 10) { } elseif (strlen($x) == 10) {
// Two's Complement // Two's Complement
$x = substr($x, -9); $x = substr($x, -9);
@ -1190,25 +1190,25 @@ class Engineering
*/ */
public static function BINTOHEX($x, $places = null) public static function BINTOHEX($x, $places = null)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places); $places = Functions::flattenSingleValue($places);
if (is_bool($x)) { if (is_bool($x)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$x = (int) $x; $x = (int) $x;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
$x = floor($x); $x = floor($x);
} }
$x = (string) $x; $x = (string) $x;
if (strlen($x) > preg_match_all('/[01]/', $x, $out)) { if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
if (strlen($x) > 10) { if (strlen($x) > 10) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} elseif (strlen($x) == 10) { } elseif (strlen($x) == 10) {
// Two's Complement // Two's Complement
return str_repeat('F', 8).substr(strtoupper(dechex(bindec(substr($x, -9)))), -2); return str_repeat('F', 8).substr(strtoupper(dechex(bindec(substr($x, -9)))), -2);
@ -1245,25 +1245,25 @@ class Engineering
*/ */
public static function BINTOOCT($x, $places = null) public static function BINTOOCT($x, $places = null)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places); $places = Functions::flattenSingleValue($places);
if (is_bool($x)) { if (is_bool($x)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$x = (int) $x; $x = (int) $x;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
$x = floor($x); $x = floor($x);
} }
$x = (string) $x; $x = (string) $x;
if (strlen($x) > preg_match_all('/[01]/', $x, $out)) { if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
if (strlen($x) > 10) { if (strlen($x) > 10) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} elseif (strlen($x) == 10) { } elseif (strlen($x) == 10) {
// Two's Complement // Two's Complement
return str_repeat('7', 7).substr(strtoupper(decoct(bindec(substr($x, -9)))), -3); return str_repeat('7', 7).substr(strtoupper(decoct(bindec(substr($x, -9)))), -3);
@ -1304,19 +1304,19 @@ class Engineering
*/ */
public static function DECTOBIN($x, $places = null) public static function DECTOBIN($x, $places = null)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places); $places = Functions::flattenSingleValue($places);
if (is_bool($x)) { if (is_bool($x)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$x = (int) $x; $x = (int) $x;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
$x = (string) $x; $x = (string) $x;
if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) { if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$x = (string) floor($x); $x = (string) floor($x);
$r = decbin($x); $r = decbin($x);
@ -1324,7 +1324,7 @@ class Engineering
// Two's Complement // Two's Complement
$r = substr($r, -10); $r = substr($r, -10);
} elseif (strlen($r) > 11) { } elseif (strlen($r) > 11) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
return self::nbrConversionFormat($r, $places); return self::nbrConversionFormat($r, $places);
@ -1361,19 +1361,19 @@ class Engineering
*/ */
public static function DECTOHEX($x, $places = null) public static function DECTOHEX($x, $places = null)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places); $places = Functions::flattenSingleValue($places);
if (is_bool($x)) { if (is_bool($x)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$x = (int) $x; $x = (int) $x;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
$x = (string) $x; $x = (string) $x;
if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) { if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$x = (string) floor($x); $x = (string) floor($x);
$r = strtoupper(dechex($x)); $r = strtoupper(dechex($x));
@ -1416,19 +1416,19 @@ class Engineering
*/ */
public static function DECTOOCT($x, $places = null) public static function DECTOOCT($x, $places = null)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places); $places = Functions::flattenSingleValue($places);
if (is_bool($x)) { if (is_bool($x)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$x = (int) $x; $x = (int) $x;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
$x = (string) $x; $x = (string) $x;
if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) { if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$x = (string) floor($x); $x = (string) floor($x);
$r = decoct($x); $r = decoct($x);
@ -1474,15 +1474,15 @@ class Engineering
*/ */
public static function HEXTOBIN($x, $places = null) public static function HEXTOBIN($x, $places = null)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places); $places = Functions::flattenSingleValue($places);
if (is_bool($x)) { if (is_bool($x)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$x = (string) $x; $x = (string) $x;
if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) { if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$binVal = decbin(hexdec($x)); $binVal = decbin(hexdec($x));
@ -1511,14 +1511,14 @@ class Engineering
*/ */
public static function HEXTODEC($x) public static function HEXTODEC($x)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
if (is_bool($x)) { if (is_bool($x)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$x = (string) $x; $x = (string) $x;
if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) { if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
return hexdec($x); return hexdec($x);
} }
@ -1558,15 +1558,15 @@ class Engineering
*/ */
public static function HEXTOOCT($x, $places = null) public static function HEXTOOCT($x, $places = null)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places); $places = Functions::flattenSingleValue($places);
if (is_bool($x)) { if (is_bool($x)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$x = (string) $x; $x = (string) $x;
if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) { if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$octVal = decoct(hexdec($x)); $octVal = decoct(hexdec($x));
@ -1610,15 +1610,15 @@ class Engineering
*/ */
public static function OCTTOBIN($x, $places = null) public static function OCTTOBIN($x, $places = null)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places); $places = Functions::flattenSingleValue($places);
if (is_bool($x)) { if (is_bool($x)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$x = (string) $x; $x = (string) $x;
if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) { if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$r = decbin(octdec($x)); $r = decbin(octdec($x));
@ -1647,14 +1647,14 @@ class Engineering
*/ */
public static function OCTTODEC($x) public static function OCTTODEC($x)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
if (is_bool($x)) { if (is_bool($x)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$x = (string) $x; $x = (string) $x;
if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) { if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
return octdec($x); return octdec($x);
} }
@ -1691,15 +1691,15 @@ class Engineering
*/ */
public static function OCTTOHEX($x, $places = null) public static function OCTTOHEX($x, $places = null)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places); $places = Functions::flattenSingleValue($places);
if (is_bool($x)) { if (is_bool($x)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$x = (string) $x; $x = (string) $x;
if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) { if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$hexVal = strtoupper(dechex(octdec($x))); $hexVal = strtoupper(dechex(octdec($x)));
@ -1725,9 +1725,9 @@ class Engineering
*/ */
public static function COMPLEX($realNumber = 0.0, $imaginary = 0.0, $suffix = 'i') public static function COMPLEX($realNumber = 0.0, $imaginary = 0.0, $suffix = 'i')
{ {
$realNumber = (is_null($realNumber)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($realNumber); $realNumber = (is_null($realNumber)) ? 0.0 : Functions::flattenSingleValue($realNumber);
$imaginary = (is_null($imaginary)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($imaginary); $imaginary = (is_null($imaginary)) ? 0.0 : Functions::flattenSingleValue($imaginary);
$suffix = (is_null($suffix)) ? 'i' : PHPExcel_Calculation_Functions::flattenSingleValue($suffix); $suffix = (is_null($suffix)) ? 'i' : Functions::flattenSingleValue($suffix);
if (((is_numeric($realNumber)) && (is_numeric($imaginary))) && if (((is_numeric($realNumber)) && (is_numeric($imaginary))) &&
(($suffix == 'i') || ($suffix == 'j') || ($suffix == ''))) { (($suffix == 'i') || ($suffix == 'j') || ($suffix == ''))) {
@ -1759,7 +1759,7 @@ class Engineering
return (string) $realNumber.$imaginary.$suffix; return (string) $realNumber.$imaginary.$suffix;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -1779,7 +1779,7 @@ class Engineering
*/ */
public static function IMAGINARY($complexNumber) public static function IMAGINARY($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
return $parsedComplex['imaginary']; return $parsedComplex['imaginary'];
@ -1801,7 +1801,7 @@ class Engineering
*/ */
public static function IMREAL($complexNumber) public static function IMREAL($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
return $parsedComplex['real']; return $parsedComplex['real'];
@ -1821,7 +1821,7 @@ class Engineering
*/ */
public static function IMABS($complexNumber) public static function IMABS($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
@ -1846,7 +1846,7 @@ class Engineering
*/ */
public static function IMARGUMENT($complexNumber) public static function IMARGUMENT($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
@ -1881,7 +1881,7 @@ class Engineering
*/ */
public static function IMCONJUGATE($complexNumber) public static function IMCONJUGATE($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
@ -1912,7 +1912,7 @@ class Engineering
*/ */
public static function IMCOS($complexNumber) public static function IMCOS($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
@ -1943,7 +1943,7 @@ class Engineering
*/ */
public static function IMSIN($complexNumber) public static function IMSIN($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
@ -1972,7 +1972,7 @@ class Engineering
*/ */
public static function IMSQRT($complexNumber) public static function IMSQRT($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
@ -2002,12 +2002,12 @@ class Engineering
*/ */
public static function IMLN($complexNumber) public static function IMLN($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$logR = log(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']))); $logR = log(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
@ -2034,12 +2034,12 @@ class Engineering
*/ */
public static function IMLOG10($complexNumber) public static function IMLOG10($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) { } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
return log10($parsedComplex['real']); return log10($parsedComplex['real']);
} }
@ -2061,12 +2061,12 @@ class Engineering
*/ */
public static function IMLOG2($complexNumber) public static function IMLOG2($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) { } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
return log($parsedComplex['real'], 2); return log($parsedComplex['real'], 2);
} }
@ -2088,7 +2088,7 @@ class Engineering
*/ */
public static function IMEXP($complexNumber) public static function IMEXP($complexNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
@ -2122,11 +2122,11 @@ class Engineering
*/ */
public static function IMPOWER($complexNumber, $realNumber) public static function IMPOWER($complexNumber, $realNumber)
{ {
$complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); $complexNumber = Functions::flattenSingleValue($complexNumber);
$realNumber = PHPExcel_Calculation_Functions::flattenSingleValue($realNumber); $realNumber = Functions::flattenSingleValue($realNumber);
if (!is_numeric($realNumber)) { if (!is_numeric($realNumber)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$parsedComplex = self::parseComplex($complexNumber); $parsedComplex = self::parseComplex($complexNumber);
@ -2158,15 +2158,15 @@ class Engineering
*/ */
public static function IMDIV($complexDividend, $complexDivisor) public static function IMDIV($complexDividend, $complexDivisor)
{ {
$complexDividend = PHPExcel_Calculation_Functions::flattenSingleValue($complexDividend); $complexDividend = Functions::flattenSingleValue($complexDividend);
$complexDivisor = PHPExcel_Calculation_Functions::flattenSingleValue($complexDivisor); $complexDivisor = Functions::flattenSingleValue($complexDivisor);
$parsedComplexDividend = self::parseComplex($complexDividend); $parsedComplexDividend = self::parseComplex($complexDividend);
$parsedComplexDivisor = self::parseComplex($complexDivisor); $parsedComplexDivisor = self::parseComplex($complexDivisor);
if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') && if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') &&
($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) { ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] == '')) { if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] == '')) {
$parsedComplexDivisor['suffix'] = $parsedComplexDividend['suffix']; $parsedComplexDivisor['suffix'] = $parsedComplexDividend['suffix'];
@ -2203,15 +2203,15 @@ class Engineering
*/ */
public static function IMSUB($complexNumber1, $complexNumber2) public static function IMSUB($complexNumber1, $complexNumber2)
{ {
$complexNumber1 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber1); $complexNumber1 = Functions::flattenSingleValue($complexNumber1);
$complexNumber2 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber2); $complexNumber2 = Functions::flattenSingleValue($complexNumber2);
$parsedComplex1 = self::parseComplex($complexNumber1); $parsedComplex1 = self::parseComplex($complexNumber1);
$parsedComplex2 = self::parseComplex($complexNumber2); $parsedComplex2 = self::parseComplex($complexNumber2);
if ((($parsedComplex1['suffix'] != '') && ($parsedComplex2['suffix'] != '')) && if ((($parsedComplex1['suffix'] != '') && ($parsedComplex2['suffix'] != '')) &&
($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) { ($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} elseif (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) { } elseif (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) {
$parsedComplex1['suffix'] = $parsedComplex2['suffix']; $parsedComplex1['suffix'] = $parsedComplex2['suffix'];
} }
@ -2241,14 +2241,14 @@ class Engineering
$activeSuffix = ''; $activeSuffix = '';
// Loop through the arguments // Loop through the arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = Functions::flattenArray(func_get_args());
foreach ($aArgs as $arg) { foreach ($aArgs as $arg) {
$parsedComplex = self::parseComplex($arg); $parsedComplex = self::parseComplex($arg);
if ($activeSuffix == '') { if ($activeSuffix == '') {
$activeSuffix = $parsedComplex['suffix']; $activeSuffix = $parsedComplex['suffix'];
} elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) { } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$returnValue['real'] += $parsedComplex['real']; $returnValue['real'] += $parsedComplex['real'];
@ -2280,7 +2280,7 @@ class Engineering
$activeSuffix = ''; $activeSuffix = '';
// Loop through the arguments // Loop through the arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = Functions::flattenArray(func_get_args());
foreach ($aArgs as $arg) { foreach ($aArgs as $arg) {
$parsedComplex = self::parseComplex($arg); $parsedComplex = self::parseComplex($arg);
@ -2288,7 +2288,7 @@ class Engineering
if (($parsedComplex['suffix'] != '') && ($activeSuffix == '')) { if (($parsedComplex['suffix'] != '') && ($activeSuffix == '')) {
$activeSuffix = $parsedComplex['suffix']; $activeSuffix = $parsedComplex['suffix'];
} elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) { } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$returnValue['real'] = ($workValue['real'] * $parsedComplex['real']) - ($workValue['imaginary'] * $parsedComplex['imaginary']); $returnValue['real'] = ($workValue['real'] * $parsedComplex['real']) - ($workValue['imaginary'] * $parsedComplex['imaginary']);
$returnValue['imaginary'] = ($workValue['real'] * $parsedComplex['imaginary']) + ($workValue['imaginary'] * $parsedComplex['real']); $returnValue['imaginary'] = ($workValue['real'] * $parsedComplex['imaginary']) + ($workValue['imaginary'] * $parsedComplex['real']);
@ -2318,8 +2318,8 @@ class Engineering
*/ */
public static function DELTA($a, $b = 0) public static function DELTA($a, $b = 0)
{ {
$a = PHPExcel_Calculation_Functions::flattenSingleValue($a); $a = Functions::flattenSingleValue($a);
$b = PHPExcel_Calculation_Functions::flattenSingleValue($b); $b = Functions::flattenSingleValue($b);
return (int) ($a == $b); return (int) ($a == $b);
} }
@ -2342,8 +2342,8 @@ class Engineering
*/ */
public static function GESTEP($number, $step = 0) public static function GESTEP($number, $step = 0)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
$step = PHPExcel_Calculation_Functions::flattenSingleValue($step); $step = Functions::flattenSingleValue($step);
return (int) ($number >= $step); return (int) ($number >= $step);
} }
@ -2397,8 +2397,8 @@ class Engineering
*/ */
public static function ERF($lower, $upper = null) public static function ERF($lower, $upper = null)
{ {
$lower = PHPExcel_Calculation_Functions::flattenSingleValue($lower); $lower = Functions::flattenSingleValue($lower);
$upper = PHPExcel_Calculation_Functions::flattenSingleValue($upper); $upper = Functions::flattenSingleValue($upper);
if (is_numeric($lower)) { if (is_numeric($lower)) {
if (is_null($upper)) { if (is_null($upper)) {
@ -2408,7 +2408,7 @@ class Engineering
return self::erfVal($upper) - self::erfVal($lower); return self::erfVal($upper) - self::erfVal($lower);
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -2463,12 +2463,12 @@ class Engineering
*/ */
public static function ERFC($x) public static function ERFC($x)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
if (is_numeric($x)) { if (is_numeric($x)) {
return self::erfcVal($x); return self::erfcVal($x);
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -2558,12 +2558,12 @@ class Engineering
*/ */
public static function CONVERTUOM($value, $fromUOM, $toUOM) public static function CONVERTUOM($value, $fromUOM, $toUOM)
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
$fromUOM = PHPExcel_Calculation_Functions::flattenSingleValue($fromUOM); $fromUOM = Functions::flattenSingleValue($fromUOM);
$toUOM = PHPExcel_Calculation_Functions::flattenSingleValue($toUOM); $toUOM = Functions::flattenSingleValue($toUOM);
if (!is_numeric($value)) { if (!is_numeric($value)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$fromMultiplier = 1.0; $fromMultiplier = 1.0;
if (isset(self::$conversionUnits[$fromUOM])) { if (isset(self::$conversionUnits[$fromUOM])) {
@ -2574,12 +2574,12 @@ class Engineering
if (isset(self::$conversionMultipliers[$fromMultiplier])) { if (isset(self::$conversionMultipliers[$fromMultiplier])) {
$fromMultiplier = self::$conversionMultipliers[$fromMultiplier]['multiplier']; $fromMultiplier = self::$conversionMultipliers[$fromMultiplier]['multiplier'];
} else { } else {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
if ((isset(self::$conversionUnits[$fromUOM])) && (self::$conversionUnits[$fromUOM]['AllowPrefix'])) { if ((isset(self::$conversionUnits[$fromUOM])) && (self::$conversionUnits[$fromUOM]['AllowPrefix'])) {
$unitGroup1 = self::$conversionUnits[$fromUOM]['Group']; $unitGroup1 = self::$conversionUnits[$fromUOM]['Group'];
} else { } else {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
} }
$value *= $fromMultiplier; $value *= $fromMultiplier;
@ -2593,16 +2593,16 @@ class Engineering
if (isset(self::$conversionMultipliers[$toMultiplier])) { if (isset(self::$conversionMultipliers[$toMultiplier])) {
$toMultiplier = self::$conversionMultipliers[$toMultiplier]['multiplier']; $toMultiplier = self::$conversionMultipliers[$toMultiplier]['multiplier'];
} else { } else {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
if ((isset(self::$conversionUnits[$toUOM])) && (self::$conversionUnits[$toUOM]['AllowPrefix'])) { if ((isset(self::$conversionUnits[$toUOM])) && (self::$conversionUnits[$toUOM]['AllowPrefix'])) {
$unitGroup2 = self::$conversionUnits[$toUOM]['Group']; $unitGroup2 = self::$conversionUnits[$toUOM]['Group'];
} else { } else {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
} }
if ($unitGroup1 != $unitGroup2) { if ($unitGroup1 != $unitGroup2) {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
if (($fromUOM == $toUOM) && ($fromMultiplier == $toMultiplier)) { if (($fromUOM == $toUOM) && ($fromMultiplier == $toMultiplier)) {

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,6 @@ define('PRECISION', 8.88E-016);
*/ */
class Functions class Functions
{ {
/** constants */ /** constants */
const COMPATIBILITY_EXCEL = 'Excel'; const COMPATIBILITY_EXCEL = 'Excel';
const COMPATIBILITY_GNUMERIC = 'Gnumeric'; const COMPATIBILITY_GNUMERIC = 'Gnumeric';
@ -94,9 +93,9 @@ class Functions
* @category Function Configuration * @category Function Configuration
* @param string $compatibilityMode Compatibility Mode * @param string $compatibilityMode Compatibility Mode
* Permitted values are: * Permitted values are:
* PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL 'Excel' * Functions::COMPATIBILITY_EXCEL 'Excel'
* PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' * Functions::COMPATIBILITY_GNUMERIC 'Gnumeric'
* PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' * Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc'
* @return boolean (Success or Failure) * @return boolean (Success or Failure)
*/ */
public static function setCompatibilityMode($compatibilityMode) public static function setCompatibilityMode($compatibilityMode)
@ -118,9 +117,9 @@ class Functions
* @category Function Configuration * @category Function Configuration
* @return string Compatibility Mode * @return string Compatibility Mode
* Possible Return values are: * Possible Return values are:
* PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL 'Excel' * Functions::COMPATIBILITY_EXCEL 'Excel'
* PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' * Functions::COMPATIBILITY_GNUMERIC 'Gnumeric'
* PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' * Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc'
*/ */
public static function getCompatibilityMode() public static function getCompatibilityMode()
{ {
@ -135,9 +134,9 @@ class Functions
* @category Function Configuration * @category Function Configuration
* @param string $returnDateType Return Date Format * @param string $returnDateType Return Date Format
* Permitted values are: * Permitted values are:
* PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC 'P' * Functions::RETURNDATE_PHP_NUMERIC 'P'
* PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT 'O' * Functions::RETURNDATE_PHP_OBJECT 'O'
* PHPExcel_Calculation_Functions::RETURNDATE_EXCEL 'E' * Functions::RETURNDATE_EXCEL 'E'
* @return boolean Success or failure * @return boolean Success or failure
*/ */
public static function setReturnDateType($returnDateType) public static function setReturnDateType($returnDateType)
@ -159,9 +158,9 @@ class Functions
* @category Function Configuration * @category Function Configuration
* @return string Return Date Format * @return string Return Date Format
* Possible Return values are: * Possible Return values are:
* PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC 'P' * Functions::RETURNDATE_PHP_NUMERIC 'P'
* PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT 'O' * Functions::RETURNDATE_PHP_OBJECT 'O'
* PHPExcel_Calculation_Functions::RETURNDATE_EXCEL 'E' * Functions::RETURNDATE_EXCEL 'E'
*/ */
public static function getReturnDateType() public static function getReturnDateType()
{ {
@ -309,7 +308,7 @@ class Functions
public static function ifCondition($condition) public static function ifCondition($condition)
{ {
$condition = PHPExcel_Calculation_Functions::flattenSingleValue($condition); $condition = Functions::flattenSingleValue($condition);
if (!isset($condition{0})) { if (!isset($condition{0})) {
$condition = '=""'; $condition = '=""';
} }

View File

@ -92,7 +92,7 @@ class PHPExcel_Calculation_Logical
$returnValue = true; $returnValue = true;
// Loop through the arguments // Loop through the arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = Functions::flattenArray(func_get_args());
$argCount = -1; $argCount = -1;
foreach ($aArgs as $argCount => $arg) { foreach ($aArgs as $argCount => $arg) {
// Is it a boolean value? // Is it a boolean value?
@ -107,7 +107,7 @@ class PHPExcel_Calculation_Logical
} elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) { } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
$arg = false; $arg = false;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$returnValue = $returnValue && ($arg != 0); $returnValue = $returnValue && ($arg != 0);
} }
@ -115,7 +115,7 @@ class PHPExcel_Calculation_Logical
// Return // Return
if ($argCount < 0) { if ($argCount < 0) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
return $returnValue; return $returnValue;
} }
@ -148,7 +148,7 @@ class PHPExcel_Calculation_Logical
$returnValue = false; $returnValue = false;
// Loop through the arguments // Loop through the arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = Functions::flattenArray(func_get_args());
$argCount = -1; $argCount = -1;
foreach ($aArgs as $argCount => $arg) { foreach ($aArgs as $argCount => $arg) {
// Is it a boolean value? // Is it a boolean value?
@ -163,7 +163,7 @@ class PHPExcel_Calculation_Logical
} elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) { } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
$arg = false; $arg = false;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$returnValue = $returnValue || ($arg != 0); $returnValue = $returnValue || ($arg != 0);
} }
@ -171,7 +171,7 @@ class PHPExcel_Calculation_Logical
// Return // Return
if ($argCount < 0) { if ($argCount < 0) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
return $returnValue; return $returnValue;
} }
@ -199,7 +199,7 @@ class PHPExcel_Calculation_Logical
*/ */
public static function NOT($logical = false) public static function NOT($logical = false)
{ {
$logical = PHPExcel_Calculation_Functions::flattenSingleValue($logical); $logical = Functions::flattenSingleValue($logical);
if (is_string($logical)) { if (is_string($logical)) {
$logical = strtoupper($logical); $logical = strtoupper($logical);
if (($logical == 'TRUE') || ($logical == PHPExcel_Calculation::getTRUE())) { if (($logical == 'TRUE') || ($logical == PHPExcel_Calculation::getTRUE())) {
@ -207,7 +207,7 @@ class PHPExcel_Calculation_Logical
} elseif (($logical == 'FALSE') || ($logical == PHPExcel_Calculation::getFALSE())) { } elseif (($logical == 'FALSE') || ($logical == PHPExcel_Calculation::getFALSE())) {
return true; return true;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
@ -248,9 +248,9 @@ class PHPExcel_Calculation_Logical
*/ */
public static function STATEMENT_IF($condition = true, $returnIfTrue = 0, $returnIfFalse = false) public static function STATEMENT_IF($condition = true, $returnIfTrue = 0, $returnIfFalse = false)
{ {
$condition = (is_null($condition)) ? true : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($condition); $condition = (is_null($condition)) ? true : (boolean) Functions::flattenSingleValue($condition);
$returnIfTrue = (is_null($returnIfTrue)) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfTrue); $returnIfTrue = (is_null($returnIfTrue)) ? 0 : Functions::flattenSingleValue($returnIfTrue);
$returnIfFalse = (is_null($returnIfFalse)) ? false : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfFalse); $returnIfFalse = (is_null($returnIfFalse)) ? false : Functions::flattenSingleValue($returnIfFalse);
return ($condition) ? $returnIfTrue : $returnIfFalse; return ($condition) ? $returnIfTrue : $returnIfFalse;
} }
@ -270,9 +270,9 @@ class PHPExcel_Calculation_Logical
*/ */
public static function IFERROR($testValue = '', $errorpart = '') public static function IFERROR($testValue = '', $errorpart = '')
{ {
$testValue = (is_null($testValue)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($testValue); $testValue = (is_null($testValue)) ? '' : Functions::flattenSingleValue($testValue);
$errorpart = (is_null($errorpart)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($errorpart); $errorpart = (is_null($errorpart)) ? '' : Functions::flattenSingleValue($errorpart);
return self::STATEMENT_IF(PHPExcel_Calculation_Functions::IS_ERROR($testValue), $errorpart, $testValue); return self::STATEMENT_IF(Functions::IS_ERROR($testValue), $errorpart, $testValue);
} }
} }

View File

@ -52,13 +52,13 @@ class LookupRef
*/ */
public static function CELL_ADDRESS($row, $column, $relativity = 1, $referenceStyle = true, $sheetText = '') public static function CELL_ADDRESS($row, $column, $relativity = 1, $referenceStyle = true, $sheetText = '')
{ {
$row = PHPExcel_Calculation_Functions::flattenSingleValue($row); $row = Functions::flattenSingleValue($row);
$column = PHPExcel_Calculation_Functions::flattenSingleValue($column); $column = Functions::flattenSingleValue($column);
$relativity = PHPExcel_Calculation_Functions::flattenSingleValue($relativity); $relativity = Functions::flattenSingleValue($relativity);
$sheetText = PHPExcel_Calculation_Functions::flattenSingleValue($sheetText); $sheetText = Functions::flattenSingleValue($sheetText);
if (($row < 1) || ($column < 1)) { if (($row < 1) || ($column < 1)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if ($sheetText > '') { if ($sheetText > '') {
@ -151,7 +151,7 @@ class LookupRef
if (is_null($cellAddress) || $cellAddress === '') { if (is_null($cellAddress) || $cellAddress === '') {
return 1; return 1;
} elseif (!is_array($cellAddress)) { } elseif (!is_array($cellAddress)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
reset($cellAddress); reset($cellAddress);
@ -229,7 +229,7 @@ class LookupRef
if (is_null($cellAddress) || $cellAddress === '') { if (is_null($cellAddress) || $cellAddress === '') {
return 1; return 1;
} elseif (!is_array($cellAddress)) { } elseif (!is_array($cellAddress)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
reset($cellAddress); reset($cellAddress);
@ -262,11 +262,11 @@ class LookupRef
$args = func_get_args(); $args = func_get_args();
$pCell = array_pop($args); $pCell = array_pop($args);
$linkURL = (is_null($linkURL)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($linkURL); $linkURL = (is_null($linkURL)) ? '' : Functions::flattenSingleValue($linkURL);
$displayName = (is_null($displayName)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($displayName); $displayName = (is_null($displayName)) ? '' : Functions::flattenSingleValue($displayName);
if ((!is_object($pCell)) || (trim($linkURL) == '')) { if ((!is_object($pCell)) || (trim($linkURL) == '')) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} }
if ((is_object($displayName)) || trim($displayName) == '') { if ((is_object($displayName)) || trim($displayName) == '') {
@ -299,9 +299,9 @@ class LookupRef
*/ */
public static function INDIRECT($cellAddress = null, PHPExcel_Cell $pCell = null) public static function INDIRECT($cellAddress = null, PHPExcel_Cell $pCell = null)
{ {
$cellAddress = PHPExcel_Calculation_Functions::flattenSingleValue($cellAddress); $cellAddress = Functions::flattenSingleValue($cellAddress);
if (is_null($cellAddress) || $cellAddress === '') { if (is_null($cellAddress) || $cellAddress === '') {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} }
$cellAddress1 = $cellAddress; $cellAddress1 = $cellAddress;
@ -313,7 +313,7 @@ class LookupRef
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress1, $matches)) || if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress1, $matches)) ||
((!is_null($cellAddress2)) && (!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress2, $matches)))) { ((!is_null($cellAddress2)) && (!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress2, $matches)))) {
if (!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $cellAddress1, $matches)) { if (!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $cellAddress1, $matches)) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} }
if (strpos($cellAddress, '!') !== false) { if (strpos($cellAddress, '!') !== false) {
@ -366,10 +366,10 @@ class LookupRef
*/ */
public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null) public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null)
{ {
$rows = PHPExcel_Calculation_Functions::flattenSingleValue($rows); $rows = Functions::flattenSingleValue($rows);
$columns = PHPExcel_Calculation_Functions::flattenSingleValue($columns); $columns = Functions::flattenSingleValue($columns);
$height = PHPExcel_Calculation_Functions::flattenSingleValue($height); $height = Functions::flattenSingleValue($height);
$width = PHPExcel_Calculation_Functions::flattenSingleValue($width); $width = Functions::flattenSingleValue($width);
if ($cellAddress == null) { if ($cellAddress == null) {
return 0; return 0;
} }
@ -377,7 +377,7 @@ class LookupRef
$args = func_get_args(); $args = func_get_args();
$pCell = array_pop($args); $pCell = array_pop($args);
if (!is_object($pCell)) { if (!is_object($pCell)) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} }
$sheetName = null; $sheetName = null;
@ -398,7 +398,7 @@ class LookupRef
$startCellColumn += $columns; $startCellColumn += $columns;
if (($startCellRow <= 0) || ($startCellColumn < 0)) { if (($startCellRow <= 0) || ($startCellColumn < 0)) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} }
$endCellColumn = PHPExcel_Cell::columnIndexFromString($endCellColumn) - 1; $endCellColumn = PHPExcel_Cell::columnIndexFromString($endCellColumn) - 1;
if (($width != null) && (!is_object($width))) { if (($width != null) && (!is_object($width))) {
@ -415,7 +415,7 @@ class LookupRef
} }
if (($endCellRow <= 0) || ($endCellColumn < 0)) { if (($endCellRow <= 0) || ($endCellColumn < 0)) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} }
$endCellColumn = PHPExcel_Cell::stringFromColumnIndex($endCellColumn); $endCellColumn = PHPExcel_Cell::stringFromColumnIndex($endCellColumn);
@ -455,7 +455,7 @@ class LookupRef
public static function CHOOSE() public static function CHOOSE()
{ {
$chooseArgs = func_get_args(); $chooseArgs = func_get_args();
$chosenEntry = PHPExcel_Calculation_Functions::flattenArray(array_shift($chooseArgs)); $chosenEntry = Functions::flattenArray(array_shift($chooseArgs));
$entryCount = count($chooseArgs) - 1; $entryCount = count($chooseArgs) - 1;
if (is_array($chosenEntry)) { if (is_array($chosenEntry)) {
@ -464,15 +464,15 @@ class LookupRef
if ((is_numeric($chosenEntry)) && (!is_bool($chosenEntry))) { if ((is_numeric($chosenEntry)) && (!is_bool($chosenEntry))) {
--$chosenEntry; --$chosenEntry;
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$chosenEntry = floor($chosenEntry); $chosenEntry = floor($chosenEntry);
if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) { if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (is_array($chooseArgs[$chosenEntry])) { if (is_array($chooseArgs[$chosenEntry])) {
return PHPExcel_Calculation_Functions::flattenArray($chooseArgs[$chosenEntry]); return Functions::flattenArray($chooseArgs[$chosenEntry]);
} else { } else {
return $chooseArgs[$chosenEntry]; return $chooseArgs[$chosenEntry];
} }
@ -494,26 +494,26 @@ class LookupRef
*/ */
public static function MATCH($lookup_value, $lookup_array, $match_type = 1) public static function MATCH($lookup_value, $lookup_array, $match_type = 1)
{ {
$lookup_array = PHPExcel_Calculation_Functions::flattenArray($lookup_array); $lookup_array = Functions::flattenArray($lookup_array);
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); $lookup_value = Functions::flattenSingleValue($lookup_value);
$match_type = (is_null($match_type)) ? 1 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($match_type); $match_type = (is_null($match_type)) ? 1 : (int) Functions::flattenSingleValue($match_type);
// MATCH is not case sensitive // MATCH is not case sensitive
$lookup_value = strtolower($lookup_value); $lookup_value = strtolower($lookup_value);
// lookup_value type has to be number, text, or logical values // lookup_value type has to be number, text, or logical values
if ((!is_numeric($lookup_value)) && (!is_string($lookup_value)) && (!is_bool($lookup_value))) { if ((!is_numeric($lookup_value)) && (!is_string($lookup_value)) && (!is_bool($lookup_value))) {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
// match_type is 0, 1 or -1 // match_type is 0, 1 or -1
if (($match_type !== 0) && ($match_type !== -1) && ($match_type !== 1)) { if (($match_type !== 0) && ($match_type !== -1) && ($match_type !== 1)) {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
// lookup_array should not be empty // lookup_array should not be empty
$lookupArraySize = count($lookup_array); $lookupArraySize = count($lookup_array);
if ($lookupArraySize <= 0) { if ($lookupArraySize <= 0) {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
// lookup_array should contain only number, text, or logical values, or empty (null) cells // lookup_array should contain only number, text, or logical values, or empty (null) cells
@ -521,7 +521,7 @@ class LookupRef
// check the type of the value // check the type of the value
if ((!is_numeric($lookupArrayValue)) && (!is_string($lookupArrayValue)) && if ((!is_numeric($lookupArrayValue)) && (!is_string($lookupArrayValue)) &&
(!is_bool($lookupArrayValue)) && (!is_null($lookupArrayValue))) { (!is_bool($lookupArrayValue)) && (!is_null($lookupArrayValue))) {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
// convert strings to lowercase for case-insensitive testing // convert strings to lowercase for case-insensitive testing
if (is_string($lookupArrayValue)) { if (is_string($lookupArrayValue)) {
@ -572,7 +572,7 @@ class LookupRef
} }
// unsuccessful in finding a match, return #N/A error value // unsuccessful in finding a match, return #N/A error value
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
@ -592,18 +592,18 @@ class LookupRef
public static function INDEX($arrayValues, $rowNum = 0, $columnNum = 0) public static function INDEX($arrayValues, $rowNum = 0, $columnNum = 0)
{ {
if (($rowNum < 0) || ($columnNum < 0)) { if (($rowNum < 0) || ($columnNum < 0)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (!is_array($arrayValues)) { if (!is_array($arrayValues)) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} }
$rowKeys = array_keys($arrayValues); $rowKeys = array_keys($arrayValues);
$columnKeys = @array_keys($arrayValues[$rowKeys[0]]); $columnKeys = @array_keys($arrayValues[$rowKeys[0]]);
if ($columnNum > count($columnKeys)) { if ($columnNum > count($columnKeys)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif ($columnNum == 0) { } elseif ($columnNum == 0) {
if ($rowNum == 0) { if ($rowNum == 0) {
return $arrayValues; return $arrayValues;
@ -625,7 +625,7 @@ class LookupRef
} }
$columnNum = $columnKeys[--$columnNum]; $columnNum = $columnKeys[--$columnNum];
if ($rowNum > count($rowKeys)) { if ($rowNum > count($rowKeys)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif ($rowNum == 0) { } elseif ($rowNum == 0) {
return $arrayValues[$columnNum]; return $arrayValues[$columnNum];
} }
@ -685,23 +685,23 @@ class LookupRef
*/ */
public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true) public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true)
{ {
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); $lookup_value = Functions::flattenSingleValue($lookup_value);
$index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number); $index_number = Functions::flattenSingleValue($index_number);
$not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match); $not_exact_match = Functions::flattenSingleValue($not_exact_match);
// index_number must be greater than or equal to 1 // index_number must be greater than or equal to 1
if ($index_number < 1) { if ($index_number < 1) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
// index_number must be less than or equal to the number of columns in lookup_array // index_number must be less than or equal to the number of columns in lookup_array
if ((!is_array($lookup_array)) || (empty($lookup_array))) { if ((!is_array($lookup_array)) || (empty($lookup_array))) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} else { } else {
$f = array_keys($lookup_array); $f = array_keys($lookup_array);
$firstRow = array_pop($f); $firstRow = array_pop($f);
if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array[$firstRow]))) { if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array[$firstRow]))) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} else { } else {
$columnKeys = array_keys($lookup_array[$firstRow]); $columnKeys = array_keys($lookup_array[$firstRow]);
$returnColumn = $columnKeys[--$index_number]; $returnColumn = $columnKeys[--$index_number];
@ -726,14 +726,14 @@ class LookupRef
if ($rowNumber !== false) { if ($rowNumber !== false) {
if ((!$not_exact_match) && ($rowValue != $lookup_value)) { if ((!$not_exact_match) && ($rowValue != $lookup_value)) {
// if an exact match is required, we have what we need to return an appropriate response // if an exact match is required, we have what we need to return an appropriate response
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} else { } else {
// otherwise return the appropriate value // otherwise return the appropriate value
return $lookup_array[$rowNumber][$returnColumn]; return $lookup_array[$rowNumber][$returnColumn];
} }
} }
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
@ -748,23 +748,23 @@ class LookupRef
*/ */
public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true) public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true)
{ {
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); $lookup_value = Functions::flattenSingleValue($lookup_value);
$index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number); $index_number = Functions::flattenSingleValue($index_number);
$not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match); $not_exact_match = Functions::flattenSingleValue($not_exact_match);
// index_number must be greater than or equal to 1 // index_number must be greater than or equal to 1
if ($index_number < 1) { if ($index_number < 1) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
// index_number must be less than or equal to the number of columns in lookup_array // index_number must be less than or equal to the number of columns in lookup_array
if ((!is_array($lookup_array)) || (empty($lookup_array))) { if ((!is_array($lookup_array)) || (empty($lookup_array))) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} else { } else {
$f = array_keys($lookup_array); $f = array_keys($lookup_array);
$firstRow = array_pop($f); $firstRow = array_pop($f);
if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array[$firstRow]))) { if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array[$firstRow]))) {
return PHPExcel_Calculation_Functions::REF(); return Functions::REF();
} else { } else {
$columnKeys = array_keys($lookup_array[$firstRow]); $columnKeys = array_keys($lookup_array[$firstRow]);
$firstkey = $f[0] - 1; $firstkey = $f[0] - 1;
@ -790,14 +790,14 @@ class LookupRef
if ($rowNumber !== false) { if ($rowNumber !== false) {
if ((!$not_exact_match) && ($rowValue != $lookup_value)) { if ((!$not_exact_match) && ($rowValue != $lookup_value)) {
// if an exact match is required, we have what we need to return an appropriate response // if an exact match is required, we have what we need to return an appropriate response
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} else { } else {
// otherwise return the appropriate value // otherwise return the appropriate value
return $lookup_array[$returnColumn][$rowNumber]; return $lookup_array[$returnColumn][$rowNumber];
} }
} }
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
@ -811,10 +811,10 @@ class LookupRef
*/ */
public static function LOOKUP($lookup_value, $lookup_vector, $result_vector = null) public static function LOOKUP($lookup_value, $lookup_vector, $result_vector = null)
{ {
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); $lookup_value = Functions::flattenSingleValue($lookup_value);
if (!is_array($lookup_vector)) { if (!is_array($lookup_vector)) {
return PHPExcel_Calculation_Functions::NA(); return Functions::NA();
} }
$lookupRows = count($lookup_vector); $lookupRows = count($lookup_vector);
$l = array_keys($lookup_vector); $l = array_keys($lookup_vector);

View File

@ -85,8 +85,8 @@ class MathTrig
*/ */
public static function ATAN2($xCoordinate = null, $yCoordinate = null) public static function ATAN2($xCoordinate = null, $yCoordinate = null)
{ {
$xCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($xCoordinate); $xCoordinate = Functions::flattenSingleValue($xCoordinate);
$yCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($yCoordinate); $yCoordinate = Functions::flattenSingleValue($yCoordinate);
$xCoordinate = ($xCoordinate !== null) ? $xCoordinate : 0.0; $xCoordinate = ($xCoordinate !== null) ? $xCoordinate : 0.0;
$yCoordinate = ($yCoordinate !== null) ? $yCoordinate : 0.0; $yCoordinate = ($yCoordinate !== null) ? $yCoordinate : 0.0;
@ -97,12 +97,12 @@ class MathTrig
$yCoordinate = (float) $yCoordinate; $yCoordinate = (float) $yCoordinate;
if (($xCoordinate == 0) && ($yCoordinate == 0)) { if (($xCoordinate == 0) && ($yCoordinate == 0)) {
return PHPExcel_Calculation_Functions::DIV0(); return Functions::DIV0();
} }
return atan2($yCoordinate, $xCoordinate); return atan2($yCoordinate, $xCoordinate);
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -125,11 +125,11 @@ class MathTrig
*/ */
public static function CEILING($number, $significance = null) public static function CEILING($number, $significance = null)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
$significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance); $significance = Functions::flattenSingleValue($significance);
if ((is_null($significance)) && if ((is_null($significance)) &&
(PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) { (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC)) {
$significance = $number / abs($number); $significance = $number / abs($number);
} }
@ -139,10 +139,10 @@ class MathTrig
} elseif (self::SIGN($number) == self::SIGN($significance)) { } elseif (self::SIGN($number) == self::SIGN($significance)) {
return ceil($number / $significance) * $significance; return ceil($number / $significance) * $significance;
} else { } else {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -163,18 +163,18 @@ class MathTrig
*/ */
public static function COMBIN($numObjs, $numInSet) public static function COMBIN($numObjs, $numInSet)
{ {
$numObjs = PHPExcel_Calculation_Functions::flattenSingleValue($numObjs); $numObjs = Functions::flattenSingleValue($numObjs);
$numInSet = PHPExcel_Calculation_Functions::flattenSingleValue($numInSet); $numInSet = Functions::flattenSingleValue($numInSet);
if ((is_numeric($numObjs)) && (is_numeric($numInSet))) { if ((is_numeric($numObjs)) && (is_numeric($numInSet))) {
if ($numObjs < $numInSet) { if ($numObjs < $numInSet) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} elseif ($numInSet < 0) { } elseif ($numInSet < 0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
return round(self::FACT($numObjs) / self::FACT($numObjs - $numInSet)) / self::FACT($numInSet); return round(self::FACT($numObjs) / self::FACT($numObjs - $numInSet)) / self::FACT($numInSet);
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -197,7 +197,7 @@ class MathTrig
*/ */
public static function EVEN($number) public static function EVEN($number)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
if (is_null($number)) { if (is_null($number)) {
return 0; return 0;
@ -209,7 +209,7 @@ class MathTrig
$significance = 2 * self::SIGN($number); $significance = 2 * self::SIGN($number);
return (int) self::CEILING($number, $significance); return (int) self::CEILING($number, $significance);
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -229,16 +229,16 @@ class MathTrig
*/ */
public static function FACT($factVal) public static function FACT($factVal)
{ {
$factVal = PHPExcel_Calculation_Functions::flattenSingleValue($factVal); $factVal = Functions::flattenSingleValue($factVal);
if (is_numeric($factVal)) { if (is_numeric($factVal)) {
if ($factVal < 0) { if ($factVal < 0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$factLoop = floor($factVal); $factLoop = floor($factVal);
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
if ($factVal > $factLoop) { if ($factVal > $factLoop) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
} }
@ -248,7 +248,7 @@ class MathTrig
} }
return $factorial ; return $factorial ;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -267,12 +267,12 @@ class MathTrig
*/ */
public static function FACTDOUBLE($factVal) public static function FACTDOUBLE($factVal)
{ {
$factLoop = PHPExcel_Calculation_Functions::flattenSingleValue($factVal); $factLoop = Functions::flattenSingleValue($factVal);
if (is_numeric($factLoop)) { if (is_numeric($factLoop)) {
$factLoop = floor($factLoop); $factLoop = floor($factLoop);
if ($factVal < 0) { if ($factVal < 0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$factorial = 1; $factorial = 1;
while ($factLoop > 1) { while ($factLoop > 1) {
@ -281,7 +281,7 @@ class MathTrig
} }
return $factorial ; return $factorial ;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -301,27 +301,27 @@ class MathTrig
*/ */
public static function FLOOR($number, $significance = null) public static function FLOOR($number, $significance = null)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
$significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance); $significance = Functions::flattenSingleValue($significance);
if ((is_null($significance)) && if ((is_null($significance)) &&
(PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) { (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC)) {
$significance = $number/abs($number); $significance = $number/abs($number);
} }
if ((is_numeric($number)) && (is_numeric($significance))) { if ((is_numeric($number)) && (is_numeric($significance))) {
if ($significance == 0.0) { if ($significance == 0.0) {
return PHPExcel_Calculation_Functions::DIV0(); return Functions::DIV0();
} elseif ($number == 0.0) { } elseif ($number == 0.0) {
return 0.0; return 0.0;
} elseif (self::SIGN($number) == self::SIGN($significance)) { } elseif (self::SIGN($number) == self::SIGN($significance)) {
return floor($number / $significance) * $significance; return floor($number / $significance) * $significance;
} else { } else {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -345,13 +345,13 @@ class MathTrig
$returnValue = 1; $returnValue = 1;
$allValuesFactors = array(); $allValuesFactors = array();
// Loop through arguments // Loop through arguments
foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $value) { foreach (Functions::flattenArray(func_get_args()) as $value) {
if (!is_numeric($value)) { if (!is_numeric($value)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} elseif ($value == 0) { } elseif ($value == 0) {
continue; continue;
} elseif ($value < 0) { } elseif ($value < 0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$myFactors = self::factors($value); $myFactors = self::factors($value);
$myCountedFactors = array_count_values($myFactors); $myCountedFactors = array_count_values($myFactors);
@ -417,7 +417,7 @@ class MathTrig
*/ */
public static function INT($number) public static function INT($number)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
if (is_null($number)) { if (is_null($number)) {
return 0; return 0;
@ -427,7 +427,7 @@ class MathTrig
if (is_numeric($number)) { if (is_numeric($number)) {
return (int) floor($number); return (int) floor($number);
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -452,14 +452,14 @@ class MathTrig
$returnValue = 1; $returnValue = 1;
$allPoweredFactors = array(); $allPoweredFactors = array();
// Loop through arguments // Loop through arguments
foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $value) { foreach (Functions::flattenArray(func_get_args()) as $value) {
if (!is_numeric($value)) { if (!is_numeric($value)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if ($value == 0) { if ($value == 0) {
return 0; return 0;
} elseif ($value < 0) { } elseif ($value < 0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$myFactors = self::factors(floor($value)); $myFactors = self::factors(floor($value));
$myCountedFactors = array_count_values($myFactors); $myCountedFactors = array_count_values($myFactors);
@ -500,14 +500,14 @@ class MathTrig
*/ */
public static function LOG_BASE($number = null, $base = 10) public static function LOG_BASE($number = null, $base = 10)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
$base = (is_null($base)) ? 10 : (float) PHPExcel_Calculation_Functions::flattenSingleValue($base); $base = (is_null($base)) ? 10 : (float) Functions::flattenSingleValue($base);
if ((!is_numeric($base)) || (!is_numeric($number))) { if ((!is_numeric($base)) || (!is_numeric($number))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (($base <= 0) || ($number <= 0)) { if (($base <= 0) || ($number <= 0)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
return log($number, $base); return log($number, $base);
} }
@ -541,7 +541,7 @@ class MathTrig
$column = 0; $column = 0;
foreach ($matrixRow as $matrixCell) { foreach ($matrixRow as $matrixCell) {
if ((is_string($matrixCell)) || ($matrixCell === null)) { if ((is_string($matrixCell)) || ($matrixCell === null)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$matrixData[$column][$row] = $matrixCell; $matrixData[$column][$row] = $matrixCell;
++$column; ++$column;
@ -552,14 +552,14 @@ class MathTrig
++$row; ++$row;
} }
if ($row != $maxColumn) { if ($row != $maxColumn) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
try { try {
$matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData); $matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData);
return $matrix->det(); return $matrix->det();
} catch (PHPExcel_Exception $ex) { } catch (PHPExcel_Exception $ex) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
@ -592,7 +592,7 @@ class MathTrig
$column = 0; $column = 0;
foreach ($matrixRow as $matrixCell) { foreach ($matrixRow as $matrixCell) {
if ((is_string($matrixCell)) || ($matrixCell === null)) { if ((is_string($matrixCell)) || ($matrixCell === null)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$matrixData[$column][$row] = $matrixCell; $matrixData[$column][$row] = $matrixCell;
++$column; ++$column;
@ -603,14 +603,14 @@ class MathTrig
++$row; ++$row;
} }
if ($row != $maxColumn) { if ($row != $maxColumn) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
try { try {
$matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData); $matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData);
return $matrix->inverse()->getArray(); return $matrix->inverse()->getArray();
} catch (PHPExcel_Exception $ex) { } catch (PHPExcel_Exception $ex) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
@ -641,7 +641,7 @@ class MathTrig
$columnA = 0; $columnA = 0;
foreach ($matrixRow as $matrixCell) { foreach ($matrixRow as $matrixCell) {
if ((!is_numeric($matrixCell)) || ($matrixCell === null)) { if ((!is_numeric($matrixCell)) || ($matrixCell === null)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$matrixAData[$rowA][$columnA] = $matrixCell; $matrixAData[$rowA][$columnA] = $matrixCell;
++$columnA; ++$columnA;
@ -657,7 +657,7 @@ class MathTrig
$columnB = 0; $columnB = 0;
foreach ($matrixRow as $matrixCell) { foreach ($matrixRow as $matrixCell) {
if ((!is_numeric($matrixCell)) || ($matrixCell === null)) { if ((!is_numeric($matrixCell)) || ($matrixCell === null)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$matrixBData[$rowB][$columnB] = $matrixCell; $matrixBData[$rowB][$columnB] = $matrixCell;
++$columnB; ++$columnB;
@ -667,13 +667,13 @@ class MathTrig
$matrixB = new PHPExcel_Shared_JAMA_Matrix($matrixBData); $matrixB = new PHPExcel_Shared_JAMA_Matrix($matrixBData);
if ($columnA != $rowB) { if ($columnA != $rowB) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
return $matrixA->times($matrixB)->getArray(); return $matrixA->times($matrixB)->getArray();
} catch (PHPExcel_Exception $ex) { } catch (PHPExcel_Exception $ex) {
var_dump($ex->getMessage()); var_dump($ex->getMessage());
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
@ -687,11 +687,11 @@ class MathTrig
*/ */
public static function MOD($a = 1, $b = 1) public static function MOD($a = 1, $b = 1)
{ {
$a = PHPExcel_Calculation_Functions::flattenSingleValue($a); $a = Functions::flattenSingleValue($a);
$b = PHPExcel_Calculation_Functions::flattenSingleValue($b); $b = Functions::flattenSingleValue($b);
if ($b == 0.0) { if ($b == 0.0) {
return PHPExcel_Calculation_Functions::DIV0(); return Functions::DIV0();
} elseif (($a < 0.0) && ($b > 0.0)) { } elseif (($a < 0.0) && ($b > 0.0)) {
return $b - fmod(abs($a), $b); return $b - fmod(abs($a), $b);
} elseif (($a > 0.0) && ($b < 0.0)) { } elseif (($a > 0.0) && ($b < 0.0)) {
@ -713,8 +713,8 @@ class MathTrig
*/ */
public static function MROUND($number, $multiple) public static function MROUND($number, $multiple)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
$multiple = PHPExcel_Calculation_Functions::flattenSingleValue($multiple); $multiple = Functions::flattenSingleValue($multiple);
if ((is_numeric($number)) && (is_numeric($multiple))) { if ((is_numeric($number)) && (is_numeric($multiple))) {
if ($multiple == 0) { if ($multiple == 0) {
@ -724,9 +724,9 @@ class MathTrig
$multiplier = 1 / $multiple; $multiplier = 1 / $multiple;
return round($number * $multiplier) / $multiplier; return round($number * $multiplier) / $multiplier;
} }
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -743,16 +743,16 @@ class MathTrig
$summer = 0; $summer = 0;
$divisor = 1; $divisor = 1;
// Loop through arguments // Loop through arguments
foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { foreach (Functions::flattenArray(func_get_args()) as $arg) {
// Is it a numeric value? // Is it a numeric value?
if (is_numeric($arg)) { if (is_numeric($arg)) {
if ($arg < 1) { if ($arg < 1) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$summer += floor($arg); $summer += floor($arg);
$divisor *= self::FACT($arg); $divisor *= self::FACT($arg);
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
@ -775,7 +775,7 @@ class MathTrig
*/ */
public static function ODD($number) public static function ODD($number)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
if (is_null($number)) { if (is_null($number)) {
return 1; return 1;
@ -794,7 +794,7 @@ class MathTrig
return (int) $result; return (int) $result;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -809,19 +809,19 @@ class MathTrig
*/ */
public static function POWER($x = 0, $y = 2) public static function POWER($x = 0, $y = 2)
{ {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = Functions::flattenSingleValue($x);
$y = PHPExcel_Calculation_Functions::flattenSingleValue($y); $y = Functions::flattenSingleValue($y);
// Validate parameters // Validate parameters
if ($x == 0.0 && $y == 0.0) { if ($x == 0.0 && $y == 0.0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} elseif ($x == 0.0 && $y < 0.0) { } elseif ($x == 0.0 && $y < 0.0) {
return PHPExcel_Calculation_Functions::DIV0(); return Functions::DIV0();
} }
// Return // Return
$result = pow($x, $y); $result = pow($x, $y);
return (!is_nan($result) && !is_infinite($result)) ? $result : PHPExcel_Calculation_Functions::NaN(); return (!is_nan($result) && !is_infinite($result)) ? $result : Functions::NaN();
} }
@ -844,7 +844,7 @@ class MathTrig
$returnValue = null; $returnValue = null;
// Loop through arguments // Loop through arguments
foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { foreach (Functions::flattenArray(func_get_args()) as $arg) {
// Is it a numeric value? // Is it a numeric value?
if ((is_numeric($arg)) && (!is_string($arg))) { if ((is_numeric($arg)) && (!is_string($arg))) {
if (is_null($returnValue)) { if (is_null($returnValue)) {
@ -883,7 +883,7 @@ class MathTrig
$returnValue = null; $returnValue = null;
// Loop through arguments // Loop through arguments
foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { foreach (Functions::flattenArray(func_get_args()) as $arg) {
// Is it a numeric value? // Is it a numeric value?
if ((is_numeric($arg)) && (!is_string($arg))) { if ((is_numeric($arg)) && (!is_string($arg))) {
if (is_null($returnValue)) { if (is_null($returnValue)) {
@ -912,8 +912,8 @@ class MathTrig
*/ */
public static function RAND($min = 0, $max = 0) public static function RAND($min = 0, $max = 0)
{ {
$min = PHPExcel_Calculation_Functions::flattenSingleValue($min); $min = Functions::flattenSingleValue($min);
$max = PHPExcel_Calculation_Functions::flattenSingleValue($max); $max = Functions::flattenSingleValue($max);
if ($min == 0 && $max == 0) { if ($min == 0 && $max == 0) {
return (mt_rand(0, 10000000)) / 10000000; return (mt_rand(0, 10000000)) / 10000000;
@ -925,10 +925,10 @@ class MathTrig
public static function ROMAN($aValue, $style = 0) public static function ROMAN($aValue, $style = 0)
{ {
$aValue = PHPExcel_Calculation_Functions::flattenSingleValue($aValue); $aValue = Functions::flattenSingleValue($aValue);
$style = (is_null($style)) ? 0 : (integer) PHPExcel_Calculation_Functions::flattenSingleValue($style); $style = (is_null($style)) ? 0 : (integer) Functions::flattenSingleValue($style);
if ((!is_numeric($aValue)) || ($aValue < 0) || ($aValue >= 4000)) { if ((!is_numeric($aValue)) || ($aValue < 0) || ($aValue >= 4000)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$aValue = (integer) $aValue; $aValue = (integer) $aValue;
if ($aValue == 0) { if ($aValue == 0) {
@ -967,8 +967,8 @@ class MathTrig
*/ */
public static function ROUNDUP($number, $digits) public static function ROUNDUP($number, $digits)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); $digits = Functions::flattenSingleValue($digits);
if ((is_numeric($number)) && (is_numeric($digits))) { if ((is_numeric($number)) && (is_numeric($digits))) {
$significance = pow(10, (int) $digits); $significance = pow(10, (int) $digits);
@ -978,7 +978,7 @@ class MathTrig
return ceil($number * $significance) / $significance; return ceil($number * $significance) / $significance;
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -993,8 +993,8 @@ class MathTrig
*/ */
public static function ROUNDDOWN($number, $digits) public static function ROUNDDOWN($number, $digits)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); $digits = Functions::flattenSingleValue($digits);
if ((is_numeric($number)) && (is_numeric($digits))) { if ((is_numeric($number)) && (is_numeric($digits))) {
$significance = pow(10, (int) $digits); $significance = pow(10, (int) $digits);
@ -1004,7 +1004,7 @@ class MathTrig
return floor($number * $significance) / $significance; return floor($number * $significance) / $significance;
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -1024,7 +1024,7 @@ class MathTrig
$returnValue = 0; $returnValue = 0;
// Loop through arguments // Loop through arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = Functions::flattenArray(func_get_args());
$x = array_shift($aArgs); $x = array_shift($aArgs);
$n = array_shift($aArgs); $n = array_shift($aArgs);
@ -1038,12 +1038,12 @@ class MathTrig
if ((is_numeric($arg)) && (!is_string($arg))) { if ((is_numeric($arg)) && (!is_string($arg))) {
$returnValue += $arg * pow($x, $n + ($m * $i++)); $returnValue += $arg * pow($x, $n + ($m * $i++));
} else { } else {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
} }
return $returnValue; return $returnValue;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -1058,7 +1058,7 @@ class MathTrig
*/ */
public static function SIGN($number) public static function SIGN($number)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
if (is_bool($number)) { if (is_bool($number)) {
return (int) $number; return (int) $number;
@ -1069,7 +1069,7 @@ class MathTrig
} }
return $number / abs($number); return $number / abs($number);
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -1083,15 +1083,15 @@ class MathTrig
*/ */
public static function SQRTPI($number) public static function SQRTPI($number)
{ {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = Functions::flattenSingleValue($number);
if (is_numeric($number)) { if (is_numeric($number)) {
if ($number < 0) { if ($number < 0) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
return sqrt($number * M_PI) ; return sqrt($number * M_PI) ;
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -1107,7 +1107,7 @@ class MathTrig
*/ */
public static function SUBTOTAL() public static function SUBTOTAL()
{ {
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = Functions::flattenArray(func_get_args());
// Calculate // Calculate
$subtotal = array_shift($aArgs); $subtotal = array_shift($aArgs);
@ -1115,30 +1115,30 @@ class MathTrig
if ((is_numeric($subtotal)) && (!is_string($subtotal))) { if ((is_numeric($subtotal)) && (!is_string($subtotal))) {
switch ($subtotal) { switch ($subtotal) {
case 1: case 1:
return PHPExcel_Calculation_Statistical::AVERAGE($aArgs); return Statistical::AVERAGE($aArgs);
case 2: case 2:
return PHPExcel_Calculation_Statistical::COUNT($aArgs); return Statistical::COUNT($aArgs);
case 3: case 3:
return PHPExcel_Calculation_Statistical::COUNTA($aArgs); return Statistical::COUNTA($aArgs);
case 4: case 4:
return PHPExcel_Calculation_Statistical::MAX($aArgs); return Statistical::MAX($aArgs);
case 5: case 5:
return PHPExcel_Calculation_Statistical::MIN($aArgs); return Statistical::MIN($aArgs);
case 6: case 6:
return self::PRODUCT($aArgs); return self::PRODUCT($aArgs);
case 7: case 7:
return PHPExcel_Calculation_Statistical::STDEV($aArgs); return Statistical::STDEV($aArgs);
case 8: case 8:
return PHPExcel_Calculation_Statistical::STDEVP($aArgs); return Statistical::STDEVP($aArgs);
case 9: case 9:
return self::SUM($aArgs); return self::SUM($aArgs);
case 10: case 10:
return PHPExcel_Calculation_Statistical::VARFunc($aArgs); return Statistical::VARFunc($aArgs);
case 11: case 11:
return PHPExcel_Calculation_Statistical::VARP($aArgs); return Statistical::VARP($aArgs);
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -1160,7 +1160,7 @@ class MathTrig
$returnValue = 0; $returnValue = 0;
// Loop through the arguments // Loop through the arguments
foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { foreach (Functions::flattenArray(func_get_args()) as $arg) {
// Is it a numeric value? // Is it a numeric value?
if ((is_numeric($arg)) && (!is_string($arg))) { if ((is_numeric($arg)) && (!is_string($arg))) {
$returnValue += $arg; $returnValue += $arg;
@ -1189,12 +1189,12 @@ class MathTrig
{ {
$returnValue = 0; $returnValue = 0;
$aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs); $aArgs = Functions::flattenArray($aArgs);
$sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs); $sumArgs = Functions::flattenArray($sumArgs);
if (empty($sumArgs)) { if (empty($sumArgs)) {
$sumArgs = $aArgs; $sumArgs = $aArgs;
} }
$condition = PHPExcel_Calculation_Functions::ifCondition($condition); $condition = Functions::ifCondition($condition);
// Loop through arguments // Loop through arguments
foreach ($aArgs as $key => $arg) { foreach ($aArgs as $key => $arg) {
if (!is_numeric($arg)) { if (!is_numeric($arg)) {
@ -1228,7 +1228,7 @@ class MathTrig
{ {
$arrayList = func_get_args(); $arrayList = func_get_args();
$wrkArray = PHPExcel_Calculation_Functions::flattenArray(array_shift($arrayList)); $wrkArray = Functions::flattenArray(array_shift($arrayList));
$wrkCellCount = count($wrkArray); $wrkCellCount = count($wrkArray);
for ($i=0; $i< $wrkCellCount; ++$i) { for ($i=0; $i< $wrkCellCount; ++$i) {
@ -1238,10 +1238,10 @@ class MathTrig
} }
foreach ($arrayList as $matrixData) { foreach ($arrayList as $matrixData) {
$array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData); $array2 = Functions::flattenArray($matrixData);
$count = count($array2); $count = count($array2);
if ($wrkCellCount != $count) { if ($wrkCellCount != $count) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
foreach ($array2 as $i => $val) { foreach ($array2 as $i => $val) {
@ -1274,7 +1274,7 @@ class MathTrig
$returnValue = 0; $returnValue = 0;
// Loop through arguments // Loop through arguments
foreach (PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $arg) { foreach (Functions::flattenArray(func_get_args()) as $arg) {
// Is it a numeric value? // Is it a numeric value?
if ((is_numeric($arg)) && (!is_string($arg))) { if ((is_numeric($arg)) && (!is_string($arg))) {
$returnValue += ($arg * $arg); $returnValue += ($arg * $arg);
@ -1294,8 +1294,8 @@ class MathTrig
*/ */
public static function SUMX2MY2($matrixData1, $matrixData2) public static function SUMX2MY2($matrixData1, $matrixData2)
{ {
$array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1); $array1 = Functions::flattenArray($matrixData1);
$array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2); $array2 = Functions::flattenArray($matrixData2);
$count = min(count($array1), count($array2)); $count = min(count($array1), count($array2));
$result = 0; $result = 0;
@ -1319,8 +1319,8 @@ class MathTrig
*/ */
public static function SUMX2PY2($matrixData1, $matrixData2) public static function SUMX2PY2($matrixData1, $matrixData2)
{ {
$array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1); $array1 = Functions::flattenArray($matrixData1);
$array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2); $array2 = Functions::flattenArray($matrixData2);
$count = min(count($array1), count($array2)); $count = min(count($array1), count($array2));
$result = 0; $result = 0;
@ -1344,8 +1344,8 @@ class MathTrig
*/ */
public static function SUMXMY2($matrixData1, $matrixData2) public static function SUMXMY2($matrixData1, $matrixData2)
{ {
$array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1); $array1 = Functions::flattenArray($matrixData1);
$array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2); $array2 = Functions::flattenArray($matrixData2);
$count = min(count($array1), count($array2)); $count = min(count($array1), count($array2));
$result = 0; $result = 0;
@ -1371,12 +1371,12 @@ class MathTrig
*/ */
public static function TRUNC($value = 0, $digits = 0) public static function TRUNC($value = 0, $digits = 0)
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); $digits = Functions::flattenSingleValue($digits);
// Validate parameters // Validate parameters
if ((!is_numeric($value)) || (!is_numeric($digits))) { if ((!is_numeric($value)) || (!is_numeric($digits))) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$digits = floor($digits); $digits = floor($digits);

File diff suppressed because it is too large Load Diff

View File

@ -47,7 +47,7 @@ class TextData
return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128); return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
} elseif (ord($c{0}) >= 254 && ord($c{0}) <= 255) { } elseif (ord($c{0}) >= 254 && ord($c{0}) <= 255) {
// error // error
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
return 0; return 0;
} }
@ -60,10 +60,10 @@ class TextData
*/ */
public static function CHARACTER($character) public static function CHARACTER($character)
{ {
$character = PHPExcel_Calculation_Functions::flattenSingleValue($character); $character = Functions::flattenSingleValue($character);
if ((!is_numeric($character)) || ($character < 0)) { if ((!is_numeric($character)) || ($character < 0)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (function_exists('mb_convert_encoding')) { if (function_exists('mb_convert_encoding')) {
@ -82,7 +82,7 @@ class TextData
*/ */
public static function TRIMNONPRINTABLE($stringValue = '') public static function TRIMNONPRINTABLE($stringValue = '')
{ {
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); $stringValue = Functions::flattenSingleValue($stringValue);
if (is_bool($stringValue)) { if (is_bool($stringValue)) {
return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
@ -107,7 +107,7 @@ class TextData
*/ */
public static function TRIMSPACES($stringValue = '') public static function TRIMSPACES($stringValue = '')
{ {
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); $stringValue = Functions::flattenSingleValue($stringValue);
if (is_bool($stringValue)) { if (is_bool($stringValue)) {
return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
} }
@ -128,11 +128,11 @@ class TextData
public static function ASCIICODE($characters) public static function ASCIICODE($characters)
{ {
if (($characters === null) || ($characters === '')) { if (($characters === null) || ($characters === '')) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
$characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters); $characters = Functions::flattenSingleValue($characters);
if (is_bool($characters)) { if (is_bool($characters)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$characters = (int) $characters; $characters = (int) $characters;
} else { } else {
$characters = ($characters) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); $characters = ($characters) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
@ -164,10 +164,10 @@ class TextData
$returnValue = ''; $returnValue = '';
// Loop through arguments // Loop through arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = Functions::flattenArray(func_get_args());
foreach ($aArgs as $arg) { foreach ($aArgs as $arg) {
if (is_bool($arg)) { if (is_bool($arg)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$arg = (int) $arg; $arg = (int) $arg;
} else { } else {
$arg = ($arg) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); $arg = ($arg) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
@ -194,12 +194,12 @@ class TextData
*/ */
public static function DOLLAR($value = 0, $decimals = 2) public static function DOLLAR($value = 0, $decimals = 2)
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
$decimals = is_null($decimals) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($decimals); $decimals = is_null($decimals) ? 0 : Functions::flattenSingleValue($decimals);
// Validate parameters // Validate parameters
if (!is_numeric($value) || !is_numeric($decimals)) { if (!is_numeric($value) || !is_numeric($decimals)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$decimals = floor($decimals); $decimals = floor($decimals);
@ -211,7 +211,7 @@ class TextData
if ($value < 0) { if ($value < 0) {
$round = 0-$round; $round = 0-$round;
} }
$value = PHPExcel_Calculation_MathTrig::MROUND($value, $round); $value = MathTrig::MROUND($value, $round);
} }
return PHPExcel_Style_NumberFormat::toFormattedString($value, $mask); return PHPExcel_Style_NumberFormat::toFormattedString($value, $mask);
@ -229,9 +229,9 @@ class TextData
*/ */
public static function SEARCHSENSITIVE($needle, $haystack, $offset = 1) public static function SEARCHSENSITIVE($needle, $haystack, $offset = 1)
{ {
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); $needle = Functions::flattenSingleValue($needle);
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); $haystack = Functions::flattenSingleValue($haystack);
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); $offset = Functions::flattenSingleValue($offset);
if (!is_bool($needle)) { if (!is_bool($needle)) {
if (is_bool($haystack)) { if (is_bool($haystack)) {
@ -252,7 +252,7 @@ class TextData
} }
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -266,9 +266,9 @@ class TextData
*/ */
public static function SEARCHINSENSITIVE($needle, $haystack, $offset = 1) public static function SEARCHINSENSITIVE($needle, $haystack, $offset = 1)
{ {
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); $needle = Functions::flattenSingleValue($needle);
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); $haystack = Functions::flattenSingleValue($haystack);
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); $offset = Functions::flattenSingleValue($offset);
if (!is_bool($needle)) { if (!is_bool($needle)) {
if (is_bool($haystack)) { if (is_bool($haystack)) {
@ -289,7 +289,7 @@ class TextData
} }
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
@ -303,13 +303,13 @@ class TextData
*/ */
public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = false) public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = false)
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
$decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals); $decimals = Functions::flattenSingleValue($decimals);
$no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas); $no_commas = Functions::flattenSingleValue($no_commas);
// Validate parameters // Validate parameters
if (!is_numeric($value) || !is_numeric($decimals)) { if (!is_numeric($value) || !is_numeric($decimals)) {
return PHPExcel_Calculation_Functions::NaN(); return Functions::NaN();
} }
$decimals = floor($decimals); $decimals = floor($decimals);
@ -334,11 +334,11 @@ class TextData
*/ */
public static function LEFT($value = '', $chars = 1) public static function LEFT($value = '', $chars = 1)
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); $chars = Functions::flattenSingleValue($chars);
if ($chars < 0) { if ($chars < 0) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (is_bool($value)) { if (is_bool($value)) {
@ -363,12 +363,12 @@ class TextData
*/ */
public static function MID($value = '', $start = 1, $chars = null) public static function MID($value = '', $start = 1, $chars = null)
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start); $start = Functions::flattenSingleValue($start);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); $chars = Functions::flattenSingleValue($chars);
if (($start < 1) || ($chars < 0)) { if (($start < 1) || ($chars < 0)) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (is_bool($value)) { if (is_bool($value)) {
@ -392,11 +392,11 @@ class TextData
*/ */
public static function RIGHT($value = '', $chars = 1) public static function RIGHT($value = '', $chars = 1)
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); $chars = Functions::flattenSingleValue($chars);
if ($chars < 0) { if ($chars < 0) {
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
if (is_bool($value)) { if (is_bool($value)) {
@ -419,7 +419,7 @@ class TextData
*/ */
public static function STRINGLENGTH($value = '') public static function STRINGLENGTH($value = '')
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
if (is_bool($value)) { if (is_bool($value)) {
$value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); $value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
@ -443,7 +443,7 @@ class TextData
*/ */
public static function LOWERCASE($mixedCaseString) public static function LOWERCASE($mixedCaseString)
{ {
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); $mixedCaseString = Functions::flattenSingleValue($mixedCaseString);
if (is_bool($mixedCaseString)) { if (is_bool($mixedCaseString)) {
$mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
@ -463,7 +463,7 @@ class TextData
*/ */
public static function UPPERCASE($mixedCaseString) public static function UPPERCASE($mixedCaseString)
{ {
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); $mixedCaseString = Functions::flattenSingleValue($mixedCaseString);
if (is_bool($mixedCaseString)) { if (is_bool($mixedCaseString)) {
$mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
@ -483,7 +483,7 @@ class TextData
*/ */
public static function PROPERCASE($mixedCaseString) public static function PROPERCASE($mixedCaseString)
{ {
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); $mixedCaseString = Functions::flattenSingleValue($mixedCaseString);
if (is_bool($mixedCaseString)) { if (is_bool($mixedCaseString)) {
$mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); $mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
@ -504,10 +504,10 @@ class TextData
*/ */
public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText) public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText)
{ {
$oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText); $oldText = Functions::flattenSingleValue($oldText);
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start); $start = Functions::flattenSingleValue($start);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); $chars = Functions::flattenSingleValue($chars);
$newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText); $newText = Functions::flattenSingleValue($newText);
$left = self::LEFT($oldText, $start-1); $left = self::LEFT($oldText, $start-1);
$right = self::RIGHT($oldText, self::STRINGLENGTH($oldText)-($start+$chars)+1); $right = self::RIGHT($oldText, self::STRINGLENGTH($oldText)-($start+$chars)+1);
@ -527,10 +527,10 @@ class TextData
*/ */
public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0)
{ {
$text = PHPExcel_Calculation_Functions::flattenSingleValue($text); $text = Functions::flattenSingleValue($text);
$fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText); $fromText = Functions::flattenSingleValue($fromText);
$toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText); $toText = Functions::flattenSingleValue($toText);
$instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance)); $instance = floor(Functions::flattenSingleValue($instance));
if ($instance == 0) { if ($instance == 0) {
if (function_exists('mb_str_replace')) { if (function_exists('mb_str_replace')) {
@ -572,7 +572,7 @@ class TextData
*/ */
public static function RETURNSTRING($testValue = '') public static function RETURNSTRING($testValue = '')
{ {
$testValue = PHPExcel_Calculation_Functions::flattenSingleValue($testValue); $testValue = Functions::flattenSingleValue($testValue);
if (is_string($testValue)) { if (is_string($testValue)) {
return $testValue; return $testValue;
@ -590,11 +590,11 @@ class TextData
*/ */
public static function TEXTFORMAT($value, $format) public static function TEXTFORMAT($value, $format)
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
$format = PHPExcel_Calculation_Functions::flattenSingleValue($format); $format = Functions::flattenSingleValue($format);
if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) { if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) {
$value = PHPExcel_Calculation_DateTime::DATEVALUE($value); $value = DateTime::DATEVALUE($value);
} }
return (string) PHPExcel_Style_NumberFormat::toFormattedString($value, $format); return (string) PHPExcel_Style_NumberFormat::toFormattedString($value, $format);
@ -608,7 +608,7 @@ class TextData
*/ */
public static function VALUE($value = '') public static function VALUE($value = '')
{ {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
if (!is_numeric($value)) { if (!is_numeric($value)) {
$numberValue = str_replace( $numberValue = str_replace(
@ -620,24 +620,24 @@ class TextData
return (float) $numberValue; return (float) $numberValue;
} }
$dateSetting = PHPExcel_Calculation_Functions::getReturnDateType(); $dateSetting = Functions::getReturnDateType();
PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
if (strpos($value, ':') !== false) { if (strpos($value, ':') !== false) {
$timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($value); $timeValue = DateTime::TIMEVALUE($value);
if ($timeValue !== PHPExcel_Calculation_Functions::VALUE()) { if ($timeValue !== Functions::VALUE()) {
PHPExcel_Calculation_Functions::setReturnDateType($dateSetting); Functions::setReturnDateType($dateSetting);
return $timeValue; return $timeValue;
} }
} }
$dateValue = PHPExcel_Calculation_DateTime::DATEVALUE($value); $dateValue = DateTime::DATEVALUE($value);
if ($dateValue !== PHPExcel_Calculation_Functions::VALUE()) { if ($dateValue !== Functions::VALUE()) {
PHPExcel_Calculation_Functions::setReturnDateType($dateSetting); Functions::setReturnDateType($dateSetting);
return $dateValue; return $dateValue;
} }
PHPExcel_Calculation_Functions::setReturnDateType($dateSetting); Functions::setReturnDateType($dateSetting);
return PHPExcel_Calculation_Functions::VALUE(); return Functions::VALUE();
} }
return (float) $value; return (float) $value;
} }

View File

@ -1,54 +0,0 @@
<?php
class AutoloaderTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
public function testAutoloaderNonPHPExcelClass()
{
$className = 'InvalidClass';
$result = PHPExcel_Autoloader::Load($className);
// Must return a boolean...
$this->assertTrue(is_bool($result));
// ... indicating failure
$this->assertFalse($result);
}
public function testAutoloaderInvalidPHPExcelClass()
{
$className = 'PHPExcel_Invalid_Class';
$result = PHPExcel_Autoloader::Load($className);
// Must return a boolean...
$this->assertTrue(is_bool($result));
// ... indicating failure
$this->assertFalse($result);
}
public function testAutoloadValidPHPExcelClass()
{
$className = 'PHPExcel_IOFactory';
$result = PHPExcel_Autoloader::Load($className);
// Check that class has been loaded
$this->assertTrue(class_exists($className));
}
public function testAutoloadInstantiateSuccess()
{
$result = new PHPExcel_Calculation_Function(1, 2, 3);
// Must return an object...
$this->assertTrue(is_object($result));
// ... of the correct type
$this->assertTrue(is_a($result, 'PHPExcel_Calculation_Function'));
}
}

View File

@ -7,19 +7,19 @@ class AdvancedValueBinderTest extends PHPUnit_Framework_TestCase
if (!defined('PHPEXCEL_ROOT')) { if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . '/Bootstrap.php');
} }
public function provider() public function provider()
{ {
if (!class_exists('PHPExcel_Style_NumberFormat')) { if (!class_exists('\\PHPExcel\\Style\\NumberFormat')) {
$this->setUp(); $this->setUp();
} }
$currencyUSD = PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE; $currencyUSD = \PHPExcel\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
$currencyEURO = str_replace('$', '€', PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); $currencyEURO = str_replace('$', '€', \PHPExcel\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
return array( return array(
array('10%', 0.1, PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00, ',', '.', '$'), array('10%', 0.1, \PHPExcel\Style\NumberFormat::FORMAT_PERCENTAGE_00, ',', '.', '$'),
array('$10.11', 10.11, $currencyUSD, ',', '.', '$'), array('$10.11', 10.11, $currencyUSD, ',', '.', '$'),
array('$1,010.12', 1010.12, $currencyUSD, ',', '.', '$'), array('$1,010.12', 1010.12, $currencyUSD, ',', '.', '$'),
array('$20,20', 20.2, $currencyUSD, '.', ',', '$'), array('$20,20', 20.2, $currencyUSD, '.', ',', '$'),

View File

@ -17,7 +17,7 @@ date_default_timezone_set('Europe/London');
// Define path to application directory // Define path to application directory
defined('APPLICATION_PATH') defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../Classes')); || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../classes'));
// Define path to application tests directory // Define path to application tests directory
defined('APPLICATION_TESTS_PATH') defined('APPLICATION_TESTS_PATH')
@ -28,7 +28,7 @@ defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'ci');
// Ensure library/ is on include_path // Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array( set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../Classes'), realpath(APPLICATION_PATH . '/../classes'),
'./', './',
dirname(__FILE__), dirname(__FILE__),
get_include_path(), get_include_path(),

View File

@ -17,15 +17,15 @@
<ini name="memory_limit" value="2048M"/> <ini name="memory_limit" value="2048M"/>
</php> </php>
<testsuite name="PHPExcel Unit Test Suite"> <testsuite name="PHPExcel Unit Test Suite">
<directory suffix="Test.php">./Classes</directory> <directory suffix="Test.php">./classes</directory>
</testsuite> </testsuite>
<filter> <filter>
<whitelist> <whitelist>
<directory suffix=".php">../Classes</directory> <directory suffix=".php">../classes</directory>
<exclude> <exclude>
<directory>../Classes/PHPExcel/Shared/PCLZip</directory> <directory>../classes/src/Shared/PCLZip</directory>
<directory>../Classes/PHPExcel/Shared/JAMA</directory> <directory>../classes/src/Shared/JAMA</directory>
<directory>../Classes/PHPExcel/Writer/PDF</directory> <directory>../classes/src/Writer/PDF</directory>
</exclude> </exclude>
</whitelist> </whitelist>
</filter> </filter>

View File

@ -17,15 +17,15 @@
<ini name="memory_limit" value="2048M"/> <ini name="memory_limit" value="2048M"/>
</php> </php>
<testsuite name="PHPExcel Unit Test Suite"> <testsuite name="PHPExcel Unit Test Suite">
<directory suffix="Test.php">./Classes</directory> <directory suffix="Test.php">./classes</directory>
</testsuite> </testsuite>
<filter> <filter>
<whitelist> <whitelist>
<directory suffix=".php">../Classes</directory> <directory suffix=".php">../classes</directory>
<exclude> <exclude>
<directory>../Classes/PHPExcel/Shared/PCLZip</directory> <directory>../classes/src/Shared/PCLZip</directory>
<directory>../Classes/PHPExcel/Shared/JAMA</directory> <directory>../classes/src/Shared/JAMA</directory>
<directory>../Classes/PHPExcel/Writer/PDF</directory> <directory>../classes/src/Writer/PDF</directory>
</exclude> </exclude>
</whitelist> </whitelist>
</filter> </filter>