Extract information functions (#2605)
* Split Information functions into a dedicated class and namespace and categorise as Value or Error * Refactor all error functions into the new ExcelError class
This commit is contained in:
parent
9c473682bc
commit
d5dc58d20e
|
|
@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
-
|
-
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
- Nothing
|
- All Excel Function implementations in `Calculation\Functions` (including the Error functions) have been moved to dedicated classes for groups of related functions. See the docblocks against all the deprecated methods for details of the new methods to call instead. At some point, these old classes will be deleted.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -595,11 +595,6 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: src/PhpSpreadsheet/Calculation/FormulaParser.php
|
path: src/PhpSpreadsheet/Calculation/FormulaParser.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Cannot call method getCell\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Functions\\:\\:ifCondition\\(\\) has no return type specified\\.$#"
|
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Functions\\:\\:ifCondition\\(\\) has no return type specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Engine\CyclicReferenceStack;
|
use PhpOffice\PhpSpreadsheet\Calculation\Engine\CyclicReferenceStack;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Engine\Logger;
|
use PhpOffice\PhpSpreadsheet\Calculation\Engine\Logger;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\Value;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Token\Stack;
|
use PhpOffice\PhpSpreadsheet\Calculation\Token\Stack;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||||
|
|
@ -973,7 +974,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'ERROR.TYPE' => [
|
'ERROR.TYPE' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'errorType'],
|
'functionCall' => [Information\ExcelError::class, 'type'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'EVEN' => [
|
'EVEN' => [
|
||||||
|
|
@ -1457,49 +1458,49 @@ class Calculation
|
||||||
],
|
],
|
||||||
'ISBLANK' => [
|
'ISBLANK' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isBlank'],
|
'functionCall' => [Information\Value::class, 'isBlank'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISERR' => [
|
'ISERR' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isErr'],
|
'functionCall' => [Information\Value::class, 'isErr'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISERROR' => [
|
'ISERROR' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isError'],
|
'functionCall' => [Information\Value::class, 'isError'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISEVEN' => [
|
'ISEVEN' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isEven'],
|
'functionCall' => [Information\Value::class, 'isEven'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISFORMULA' => [
|
'ISFORMULA' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isFormula'],
|
'functionCall' => [Information\Value::class, 'isFormula'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
'passCellReference' => true,
|
'passCellReference' => true,
|
||||||
'passByReference' => [true],
|
'passByReference' => [true],
|
||||||
],
|
],
|
||||||
'ISLOGICAL' => [
|
'ISLOGICAL' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isLogical'],
|
'functionCall' => [Information\Value::class, 'isLogical'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISNA' => [
|
'ISNA' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isNa'],
|
'functionCall' => [Information\Value::class, 'isNa'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISNONTEXT' => [
|
'ISNONTEXT' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isNonText'],
|
'functionCall' => [Information\Value::class, 'isNonText'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISNUMBER' => [
|
'ISNUMBER' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isNumber'],
|
'functionCall' => [Information\Value::class, 'isNumber'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISO.CEILING' => [
|
'ISO.CEILING' => [
|
||||||
|
|
@ -1509,7 +1510,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'ISODD' => [
|
'ISODD' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isOdd'],
|
'functionCall' => [Information\Value::class, 'isOdd'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISOWEEKNUM' => [
|
'ISOWEEKNUM' => [
|
||||||
|
|
@ -1529,7 +1530,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'ISTEXT' => [
|
'ISTEXT' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'isText'],
|
'functionCall' => [Information\Value::class, 'isText'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ISTHAIDIGIT' => [
|
'ISTHAIDIGIT' => [
|
||||||
|
|
@ -1759,7 +1760,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'N' => [
|
'N' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'n'],
|
'functionCall' => [Information\Value::class, 'asNumber'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'NA' => [
|
'NA' => [
|
||||||
|
|
@ -2559,7 +2560,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'TYPE' => [
|
'TYPE' => [
|
||||||
'category' => Category::CATEGORY_INFORMATION,
|
'category' => Category::CATEGORY_INFORMATION,
|
||||||
'functionCall' => [Functions::class, 'TYPE'],
|
'functionCall' => [Information\Value::class, 'type'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'UNICHAR' => [
|
'UNICHAR' => [
|
||||||
|
|
@ -3252,7 +3253,7 @@ class Calculation
|
||||||
return self::FORMULA_STRING_QUOTE . $value . self::FORMULA_STRING_QUOTE;
|
return self::FORMULA_STRING_QUOTE . $value . self::FORMULA_STRING_QUOTE;
|
||||||
} elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
|
} elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
|
||||||
// Convert numeric errors to NaN error
|
// Convert numeric errors to NaN error
|
||||||
return Functions::NAN();
|
return Information\ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
@ -3273,7 +3274,7 @@ class Calculation
|
||||||
}
|
}
|
||||||
// Convert numeric errors to NAN error
|
// Convert numeric errors to NAN error
|
||||||
} elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
|
} elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
|
||||||
return Functions::NAN();
|
return Information\ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
@ -3342,7 +3343,7 @@ class Calculation
|
||||||
self::$returnArrayAsType = $returnArrayAsType;
|
self::$returnArrayAsType = $returnArrayAsType;
|
||||||
$testResult = Functions::flattenArray($result);
|
$testResult = Functions::flattenArray($result);
|
||||||
if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) {
|
if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) {
|
||||||
return Functions::VALUE();
|
return Information\ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
// If there's only a single cell in the array, then we allow it
|
// If there's only a single cell in the array, then we allow it
|
||||||
if (count($testResult) != 1) {
|
if (count($testResult) != 1) {
|
||||||
|
|
@ -3350,13 +3351,13 @@ class Calculation
|
||||||
$r = array_keys($result);
|
$r = array_keys($result);
|
||||||
$r = array_shift($r);
|
$r = array_shift($r);
|
||||||
if (!is_numeric($r)) {
|
if (!is_numeric($r)) {
|
||||||
return Functions::VALUE();
|
return Information\ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
if (is_array($result[$r])) {
|
if (is_array($result[$r])) {
|
||||||
$c = array_keys($result[$r]);
|
$c = array_keys($result[$r]);
|
||||||
$c = array_shift($c);
|
$c = array_shift($c);
|
||||||
if (!is_numeric($c)) {
|
if (!is_numeric($c)) {
|
||||||
return Functions::VALUE();
|
return Information\ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3367,7 +3368,7 @@ class Calculation
|
||||||
if ($result === null && $cell->getWorksheet()->getSheetView()->getShowZeros()) {
|
if ($result === null && $cell->getWorksheet()->getSheetView()->getShowZeros()) {
|
||||||
return 0;
|
return 0;
|
||||||
} elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
|
} elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
|
||||||
return Functions::NAN();
|
return Information\ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
@ -4428,7 +4429,7 @@ class Calculation
|
||||||
isset($storeValue)
|
isset($storeValue)
|
||||||
&& (
|
&& (
|
||||||
!$storeValueAsBool
|
!$storeValueAsBool
|
||||||
|| Functions::isError($storeValue)
|
|| Value::isError($storeValue)
|
||||||
|| ($storeValue === 'Pruned branch')
|
|| ($storeValue === 'Pruned branch')
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
|
@ -4463,7 +4464,7 @@ class Calculation
|
||||||
isset($storeValue)
|
isset($storeValue)
|
||||||
&& (
|
&& (
|
||||||
$storeValueAsBool
|
$storeValueAsBool
|
||||||
|| Functions::isError($storeValue)
|
|| Value::isError($storeValue)
|
||||||
|| ($storeValue === 'Pruned branch')
|
|| ($storeValue === 'Pruned branch')
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
|
@ -4569,7 +4570,7 @@ class Calculation
|
||||||
|
|
||||||
$stack->push('Cell Reference', $cellValue, $cellRef);
|
$stack->push('Cell Reference', $cellValue, $cellRef);
|
||||||
} else {
|
} else {
|
||||||
$stack->push('Error', Functions::REF(), null);
|
$stack->push('Error', Information\ExcelError::REF(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -4704,7 +4705,7 @@ class Calculation
|
||||||
if (isset($matches[8])) {
|
if (isset($matches[8])) {
|
||||||
if ($cell === null) {
|
if ($cell === null) {
|
||||||
// We can't access the range, so return a REF error
|
// We can't access the range, so return a REF error
|
||||||
$cellValue = Functions::REF();
|
$cellValue = Information\ExcelError::REF();
|
||||||
} else {
|
} else {
|
||||||
$cellRef = $matches[6] . $matches[7] . ':' . $matches[9] . $matches[10];
|
$cellRef = $matches[6] . $matches[7] . ':' . $matches[9] . $matches[10];
|
||||||
if ($matches[2] > '') {
|
if ($matches[2] > '') {
|
||||||
|
|
@ -4734,7 +4735,7 @@ class Calculation
|
||||||
} else {
|
} else {
|
||||||
if ($cell === null) {
|
if ($cell === null) {
|
||||||
// We can't access the cell, so return a REF error
|
// We can't access the cell, so return a REF error
|
||||||
$cellValue = Functions::REF();
|
$cellValue = Information\ExcelError::REF();
|
||||||
} else {
|
} else {
|
||||||
$cellRef = $matches[6] . $matches[7];
|
$cellRef = $matches[6] . $matches[7];
|
||||||
if ($matches[2] > '') {
|
if ($matches[2] > '') {
|
||||||
|
|
@ -5069,7 +5070,7 @@ class Calculation
|
||||||
((is_string($operand1) && !is_numeric($operand1) && strlen($operand1) > 0) ||
|
((is_string($operand1) && !is_numeric($operand1) && strlen($operand1) > 0) ||
|
||||||
(is_string($operand2) && !is_numeric($operand2) && strlen($operand2) > 0))
|
(is_string($operand2) && !is_numeric($operand2) && strlen($operand2) > 0))
|
||||||
) {
|
) {
|
||||||
$result = Functions::VALUE();
|
$result = Information\ExcelError::VALUE();
|
||||||
} else {
|
} else {
|
||||||
// If we're dealing with non-matrix operations, execute the necessary operation
|
// If we're dealing with non-matrix operations, execute the necessary operation
|
||||||
switch ($operation) {
|
switch ($operation) {
|
||||||
|
|
@ -5217,7 +5218,7 @@ class Calculation
|
||||||
// Named range?
|
// Named range?
|
||||||
$namedRange = DefinedName::resolveName($range, $worksheet);
|
$namedRange = DefinedName::resolveName($range, $worksheet);
|
||||||
if ($namedRange === null) {
|
if ($namedRange === null) {
|
||||||
return Functions::REF();
|
return Information\ExcelError::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
$worksheet = $namedRange->getWorksheet();
|
$worksheet = $namedRange->getWorksheet();
|
||||||
|
|
@ -5406,7 +5407,7 @@ class Calculation
|
||||||
$definedNameScope = $namedRange->getScope();
|
$definedNameScope = $namedRange->getScope();
|
||||||
if ($definedNameScope !== null && $definedNameScope !== $cellWorksheet) {
|
if ($definedNameScope !== null && $definedNameScope !== $cellWorksheet) {
|
||||||
// The defined name isn't in our current scope, so #REF
|
// The defined name isn't in our current scope, so #REF
|
||||||
$result = Functions::REF();
|
$result = Information\ExcelError::REF();
|
||||||
$stack->push('Error', $result, $namedRange->getName());
|
$stack->push('Error', $result, $namedRange->getName());
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Database;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Database;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class DGet extends DatabaseAbstract
|
class DGet extends DatabaseAbstract
|
||||||
{
|
{
|
||||||
|
|
@ -41,7 +41,7 @@ class DGet extends DatabaseAbstract
|
||||||
|
|
||||||
$columnData = self::getFilteredColumn($database, $field, $criteria);
|
$columnData = self::getFilteredColumn($database, $field, $criteria);
|
||||||
if (count($columnData) > 1) {
|
if (count($columnData) > 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$row = array_pop($columnData);
|
$row = array_pop($columnData);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Current
|
class Current
|
||||||
{
|
{
|
||||||
|
|
@ -29,7 +29,7 @@ class Current
|
||||||
$dti = new DateTimeImmutable();
|
$dti = new DateTimeImmutable();
|
||||||
$dateArray = Helpers::dateParse($dti->format('c'));
|
$dateArray = Helpers::dateParse($dti->format('c'));
|
||||||
|
|
||||||
return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray, true) : Functions::VALUE();
|
return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray, true) : ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,6 +54,6 @@ class Current
|
||||||
$dti = new DateTimeImmutable();
|
$dti = new DateTimeImmutable();
|
||||||
$dateArray = Helpers::dateParse($dti->format('c'));
|
$dateArray = Helpers::dateParse($dti->format('c'));
|
||||||
|
|
||||||
return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray) : Functions::VALUE();
|
return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray) : ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||||
|
|
||||||
|
|
@ -95,15 +95,15 @@ class Date
|
||||||
{
|
{
|
||||||
$year = ($year !== null) ? StringHelper::testStringAsNumeric((string) $year) : 0;
|
$year = ($year !== null) ? StringHelper::testStringAsNumeric((string) $year) : 0;
|
||||||
if (!is_numeric($year)) {
|
if (!is_numeric($year)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
$year = (int) $year;
|
$year = (int) $year;
|
||||||
|
|
||||||
if ($year < ($baseYear - 1900)) {
|
if ($year < ($baseYear - 1900)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
if ((($baseYear - 1900) !== 0) && ($year < $baseYear) && ($year >= 1900)) {
|
if ((($baseYear - 1900) !== 0) && ($year < $baseYear) && ($year >= 1900)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($year < $baseYear) && ($year >= ($baseYear - 1900))) {
|
if (($year < $baseYear) && ($year >= ($baseYear - 1900))) {
|
||||||
|
|
@ -126,7 +126,7 @@ class Date
|
||||||
|
|
||||||
$month = ($month !== null) ? StringHelper::testStringAsNumeric((string) $month) : 0;
|
$month = ($month !== null) ? StringHelper::testStringAsNumeric((string) $month) : 0;
|
||||||
if (!is_numeric($month)) {
|
if (!is_numeric($month)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $month;
|
return (int) $month;
|
||||||
|
|
@ -145,7 +145,7 @@ class Date
|
||||||
|
|
||||||
$day = ($day !== null) ? StringHelper::testStringAsNumeric((string) $day) : 0;
|
$day = ($day !== null) ? StringHelper::testStringAsNumeric((string) $day) : 0;
|
||||||
if (!is_numeric($day)) {
|
if (!is_numeric($day)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $day;
|
return (int) $day;
|
||||||
|
|
@ -166,7 +166,7 @@ class Date
|
||||||
|
|
||||||
// Re-validate the year parameter after adjustments
|
// Re-validate the year parameter after adjustments
|
||||||
if (($year < $baseYear) || ($year >= 10000)) {
|
if (($year < $baseYear) || ($year >= 10000)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class DateValue
|
class DateValue
|
||||||
|
|
@ -59,7 +59,7 @@ class DateValue
|
||||||
foreach ($t1 as &$t) {
|
foreach ($t1 as &$t) {
|
||||||
if ((is_numeric($t)) && ($t > 31)) {
|
if ((is_numeric($t)) && ($t > 31)) {
|
||||||
if ($yearFound) {
|
if ($yearFound) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
if ($t < 100) {
|
if ($t < 100) {
|
||||||
$t += 1900;
|
$t += 1900;
|
||||||
|
|
@ -69,7 +69,7 @@ class DateValue
|
||||||
}
|
}
|
||||||
if (count($t1) === 1) {
|
if (count($t1) === 1) {
|
||||||
// We've been fed a time value without any date
|
// We've been fed a time value without any date
|
||||||
return ((strpos((string) $t, ':') === false)) ? Functions::Value() : 0.0;
|
return ((strpos((string) $t, ':') === false)) ? ExcelError::Value() : 0.0;
|
||||||
}
|
}
|
||||||
unset($t);
|
unset($t);
|
||||||
|
|
||||||
|
|
@ -131,12 +131,12 @@ class DateValue
|
||||||
*/
|
*/
|
||||||
private static function finalResults(array $PHPDateArray, DateTimeImmutable $dti, int $baseYear)
|
private static function finalResults(array $PHPDateArray, DateTimeImmutable $dti, int $baseYear)
|
||||||
{
|
{
|
||||||
$retValue = Functions::Value();
|
$retValue = ExcelError::Value();
|
||||||
if (Helpers::dateParseSucceeded($PHPDateArray)) {
|
if (Helpers::dateParseSucceeded($PHPDateArray)) {
|
||||||
// Execute function
|
// Execute function
|
||||||
Helpers::replaceIfEmpty($PHPDateArray['year'], $dti->format('Y'));
|
Helpers::replaceIfEmpty($PHPDateArray['year'], $dti->format('Y'));
|
||||||
if ($PHPDateArray['year'] < $baseYear) {
|
if ($PHPDateArray['year'] < $baseYear) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
Helpers::replaceIfEmpty($PHPDateArray['month'], $dti->format('m'));
|
Helpers::replaceIfEmpty($PHPDateArray['month'], $dti->format('m'));
|
||||||
Helpers::replaceIfEmpty($PHPDateArray['day'], $dti->format('d'));
|
Helpers::replaceIfEmpty($PHPDateArray['day'], $dti->format('d'));
|
||||||
|
|
@ -147,7 +147,7 @@ class DateValue
|
||||||
$day = (int) $PHPDateArray['day'];
|
$day = (int) $PHPDateArray['day'];
|
||||||
$year = (int) $PHPDateArray['year'];
|
$year = (int) $PHPDateArray['year'];
|
||||||
if (!checkdate($month, $day, $year)) {
|
if (!checkdate($month, $day, $year)) {
|
||||||
return ($year === 1900 && $month === 2 && $day === 29) ? Helpers::returnIn3FormatsFloat(60.0) : Functions::VALUE();
|
return ($year === 1900 && $month === 2 && $day === 29) ? Helpers::returnIn3FormatsFloat(60.0) : ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
$retValue = Helpers::returnIn3FormatsArray($PHPDateArray, true);
|
$retValue = Helpers::returnIn3FormatsArray($PHPDateArray, true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Days
|
class Days
|
||||||
|
|
@ -48,7 +48,7 @@ class Days
|
||||||
$PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate);
|
$PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate);
|
||||||
$PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate);
|
$PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate);
|
||||||
|
|
||||||
$days = Functions::VALUE();
|
$days = ExcelError::VALUE();
|
||||||
$diff = $PHPStartDateObject->diff($PHPEndDateObject);
|
$diff = $PHPStartDateObject->diff($PHPEndDateObject);
|
||||||
if ($diff !== false && !is_bool($diff->days)) {
|
if ($diff !== false && !is_bool($diff->days)) {
|
||||||
$days = $diff->days;
|
$days = $diff->days;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Days360
|
class Days360
|
||||||
|
|
@ -58,7 +58,7 @@ class Days360
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_bool($method)) {
|
if (!is_bool($method)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Difference
|
class Difference
|
||||||
|
|
@ -65,14 +65,14 @@ class Difference
|
||||||
$retVal = self::replaceRetValue($retVal, $unit, 'YD') ?? self::datedifYD($difference, $startYears, $endYears, $PHPStartDateObject, $PHPEndDateObject);
|
$retVal = self::replaceRetValue($retVal, $unit, 'YD') ?? self::datedifYD($difference, $startYears, $endYears, $PHPStartDateObject, $PHPEndDateObject);
|
||||||
$retVal = self::replaceRetValue($retVal, $unit, 'YM') ?? self::datedifYM($PHPDiffDateObject);
|
$retVal = self::replaceRetValue($retVal, $unit, 'YM') ?? self::datedifYM($PHPDiffDateObject);
|
||||||
|
|
||||||
return is_bool($retVal) ? Functions::VALUE() : $retVal;
|
return is_bool($retVal) ? ExcelError::VALUE() : $retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function initialDiff(float $startDate, float $endDate): float
|
private static function initialDiff(float $startDate, float $endDate): float
|
||||||
{
|
{
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($startDate > $endDate) {
|
if ($startDate > $endDate) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $endDate - $startDate;
|
return $endDate - $startDate;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Helpers
|
class Helpers
|
||||||
|
|
@ -33,7 +34,7 @@ class Helpers
|
||||||
if (is_object($dateValue)) {
|
if (is_object($dateValue)) {
|
||||||
$retval = SharedDateHelper::PHPToExcel($dateValue);
|
$retval = SharedDateHelper::PHPToExcel($dateValue);
|
||||||
if (is_bool($retval)) {
|
if (is_bool($retval)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $retval;
|
return $retval;
|
||||||
|
|
@ -46,11 +47,11 @@ class Helpers
|
||||||
$dateValue = DateValue::fromString($dateValue);
|
$dateValue = DateValue::fromString($dateValue);
|
||||||
Functions::setReturnDateType($saveReturnDateType);
|
Functions::setReturnDateType($saveReturnDateType);
|
||||||
if (!is_numeric($dateValue)) {
|
if (!is_numeric($dateValue)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($dateValue < 0 && Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) {
|
if ($dateValue < 0 && Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (float) $dateValue;
|
return (float) $dateValue;
|
||||||
|
|
@ -253,7 +254,7 @@ class Helpers
|
||||||
return (float) $number;
|
return (float) $number;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -266,13 +267,13 @@ class Helpers
|
||||||
public static function validateNotNegative($number)
|
public static function validateNotNegative($number)
|
||||||
{
|
{
|
||||||
if (!is_numeric($number)) {
|
if (!is_numeric($number)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
if ($number >= 0) {
|
if ($number >= 0) {
|
||||||
return (float) $number;
|
return (float) $number;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function silly1900(DateTime $PHPDateObject, string $mod = '-1 day'): void
|
public static function silly1900(DateTime $PHPDateObject, string $mod = '-1 day'): void
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use DateTime;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Time
|
class Time
|
||||||
|
|
@ -62,7 +63,7 @@ class Time
|
||||||
if ($hour > 23) {
|
if ($hour > 23) {
|
||||||
$hour = $hour % 24;
|
$hour = $hour % 24;
|
||||||
} elseif ($hour < 0) {
|
} elseif ($hour < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
|
|
@ -121,7 +122,7 @@ class Time
|
||||||
$value = (int) $value;
|
$value = (int) $value;
|
||||||
}
|
}
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $value;
|
return (int) $value;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use Datetime;
|
use Datetime;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class TimeValue
|
class TimeValue
|
||||||
|
|
@ -51,7 +52,7 @@ class TimeValue
|
||||||
}
|
}
|
||||||
|
|
||||||
$PHPDateArray = Helpers::dateParse($timeValue);
|
$PHPDateArray = Helpers::dateParse($timeValue);
|
||||||
$retValue = Functions::VALUE();
|
$retValue = ExcelError::VALUE();
|
||||||
if (Helpers::dateParseSucceeded($PHPDateArray)) {
|
if (Helpers::dateParseSucceeded($PHPDateArray)) {
|
||||||
/** @var int */
|
/** @var int */
|
||||||
$hour = $PHPDateArray['hour'];
|
$hour = $PHPDateArray['hour'];
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Week
|
class Week
|
||||||
|
|
@ -192,11 +192,11 @@ class Week
|
||||||
private static function validateStyle($style): int
|
private static function validateStyle($style): int
|
||||||
{
|
{
|
||||||
if (!is_numeric($style)) {
|
if (!is_numeric($style)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
$style = (int) $style;
|
$style = (int) $style;
|
||||||
if (($style < 1) || ($style > 3)) {
|
if (($style < 1) || ($style > 3)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $style;
|
return $style;
|
||||||
|
|
@ -233,7 +233,7 @@ class Week
|
||||||
private static function validateDateValue($dateValue): float
|
private static function validateDateValue($dateValue): float
|
||||||
{
|
{
|
||||||
if (is_bool($dateValue)) {
|
if (is_bool($dateValue)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Helpers::getDateValue($dateValue);
|
return Helpers::getDateValue($dateValue);
|
||||||
|
|
@ -251,12 +251,12 @@ class Week
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($method)) {
|
if (!is_numeric($method)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
$method = (int) $method;
|
$method = (int) $method;
|
||||||
if (!array_key_exists($method, Constants::METHODARR)) {
|
if (!array_key_exists($method, Constants::METHODARR)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
$method = Constants::METHODARR[$method];
|
$method = Constants::METHODARR[$method];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class YearFrac
|
class YearFrac
|
||||||
|
|
@ -73,7 +74,7 @@ class YearFrac
|
||||||
return Functions::scalar(Days360::between($startDate, $endDate, true)) / 360;
|
return Functions::scalar(Days360::between($startDate, $endDate, true)) / 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class BesselI
|
class BesselI
|
||||||
{
|
{
|
||||||
|
|
@ -49,12 +49,12 @@ class BesselI
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ord < 0) {
|
if ($ord < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$fResult = self::calculate($x, $ord);
|
$fResult = self::calculate($x, $ord);
|
||||||
|
|
||||||
return (is_nan($fResult)) ? Functions::NAN() : $fResult;
|
return (is_nan($fResult)) ? ExcelError::NAN() : $fResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function calculate(float $x, int $ord): float
|
private static function calculate(float $x, int $ord): float
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class BesselJ
|
class BesselJ
|
||||||
{
|
{
|
||||||
|
|
@ -48,12 +48,12 @@ class BesselJ
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ord < 0) {
|
if ($ord < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$fResult = self::calculate($x, $ord);
|
$fResult = self::calculate($x, $ord);
|
||||||
|
|
||||||
return (is_nan($fResult)) ? Functions::NAN() : $fResult;
|
return (is_nan($fResult)) ? ExcelError::NAN() : $fResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function calculate(float $x, int $ord): float
|
private static function calculate(float $x, int $ord): float
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class BesselK
|
class BesselK
|
||||||
{
|
{
|
||||||
|
|
@ -46,12 +47,12 @@ class BesselK
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($ord < 0) || ($x <= 0.0)) {
|
if (($ord < 0) || ($x <= 0.0)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$fBk = self::calculate($x, $ord);
|
$fBk = self::calculate($x, $ord);
|
||||||
|
|
||||||
return (is_nan($fBk)) ? Functions::NAN() : $fBk;
|
return (is_nan($fBk)) ? ExcelError::NAN() : $fBk;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function calculate(float $x, int $ord): float
|
private static function calculate(float $x, int $ord): float
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class BesselY
|
class BesselY
|
||||||
{
|
{
|
||||||
|
|
@ -45,12 +45,12 @@ class BesselY
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($ord < 0) || ($x <= 0.0)) {
|
if (($ord < 0) || ($x <= 0.0)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$fBy = self::calculate($x, $ord);
|
$fBy = self::calculate($x, $ord);
|
||||||
|
|
||||||
return (is_nan($fBy)) ? Functions::NAN() : $fBy;
|
return (is_nan($fBy)) ? ExcelError::NAN() : $fBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function calculate(float $x, int $ord): float
|
private static function calculate(float $x, int $ord): float
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class BitWise
|
class BitWise
|
||||||
{
|
{
|
||||||
|
|
@ -161,7 +162,7 @@ class BitWise
|
||||||
|
|
||||||
$result = floor($number * (2 ** $shiftAmount));
|
$result = floor($number * (2 ** $shiftAmount));
|
||||||
if ($result > 2 ** 48 - 1) {
|
if ($result > 2 ** 48 - 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
@ -199,7 +200,7 @@ class BitWise
|
||||||
|
|
||||||
$result = floor($number / (2 ** $shiftAmount));
|
$result = floor($number / (2 ** $shiftAmount));
|
||||||
if ($result > 2 ** 48 - 1) { // possible because shiftAmount can be negative
|
if ($result > 2 ** 48 - 1) { // possible because shiftAmount can be negative
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
@ -219,16 +220,16 @@ class BitWise
|
||||||
if (is_numeric($value)) {
|
if (is_numeric($value)) {
|
||||||
if ($value == floor($value)) {
|
if ($value == floor($value)) {
|
||||||
if (($value > 2 ** 48 - 1) || ($value < 0)) {
|
if (($value > 2 ** 48 - 1) || ($value < 0)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return floor($value);
|
return floor($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -244,13 +245,13 @@ class BitWise
|
||||||
|
|
||||||
if (is_numeric($value)) {
|
if (is_numeric($value)) {
|
||||||
if (abs($value) > 53) {
|
if (abs($value) > 53) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $value;
|
return (int) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use Complex\Complex as ComplexObject;
|
||||||
use Complex\Exception as ComplexException;
|
use Complex\Exception as ComplexException;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Complex
|
class Complex
|
||||||
{
|
{
|
||||||
|
|
@ -55,7 +55,7 @@ class Complex
|
||||||
return (string) $complex;
|
return (string) $complex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -83,7 +83,7 @@ class Complex
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $complex->getImaginary();
|
return $complex->getImaginary();
|
||||||
|
|
@ -113,7 +113,7 @@ class Complex
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $complex->getReal();
|
return $complex->getReal();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use Complex\Complex as ComplexObject;
|
use Complex\Complex as ComplexObject;
|
||||||
use Complex\Exception as ComplexException;
|
use Complex\Exception as ComplexException;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class ComplexFunctions
|
class ComplexFunctions
|
||||||
{
|
{
|
||||||
|
|
@ -35,7 +35,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $complex->abs();
|
return $complex->abs();
|
||||||
|
|
@ -66,11 +66,11 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $complex->argument();
|
return $complex->argument();
|
||||||
|
|
@ -100,7 +100,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->conjugate();
|
return (string) $complex->conjugate();
|
||||||
|
|
@ -130,7 +130,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->cos();
|
return (string) $complex->cos();
|
||||||
|
|
@ -160,7 +160,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->cosh();
|
return (string) $complex->cosh();
|
||||||
|
|
@ -190,7 +190,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->cot();
|
return (string) $complex->cot();
|
||||||
|
|
@ -220,7 +220,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->csc();
|
return (string) $complex->csc();
|
||||||
|
|
@ -250,7 +250,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->csch();
|
return (string) $complex->csch();
|
||||||
|
|
@ -280,7 +280,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->sin();
|
return (string) $complex->sin();
|
||||||
|
|
@ -310,7 +310,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->sinh();
|
return (string) $complex->sinh();
|
||||||
|
|
@ -340,7 +340,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->sec();
|
return (string) $complex->sec();
|
||||||
|
|
@ -370,7 +370,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->sech();
|
return (string) $complex->sech();
|
||||||
|
|
@ -400,7 +400,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->tan();
|
return (string) $complex->tan();
|
||||||
|
|
@ -430,11 +430,11 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$theta = self::IMARGUMENT($complexNumber);
|
$theta = self::IMARGUMENT($complexNumber);
|
||||||
if ($theta === Functions::DIV0()) {
|
if ($theta === ExcelError::DIV0()) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -465,11 +465,11 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->ln();
|
return (string) $complex->ln();
|
||||||
|
|
@ -499,11 +499,11 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->log10();
|
return (string) $complex->log10();
|
||||||
|
|
@ -533,11 +533,11 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->log2();
|
return (string) $complex->log2();
|
||||||
|
|
@ -567,7 +567,7 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->exp();
|
return (string) $complex->exp();
|
||||||
|
|
@ -599,11 +599,11 @@ class ComplexFunctions
|
||||||
try {
|
try {
|
||||||
$complex = new ComplexObject($complexNumber);
|
$complex = new ComplexObject($complexNumber);
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($realNumber)) {
|
if (!is_numeric($realNumber)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $complex->pow((float) $realNumber);
|
return (string) $complex->pow((float) $realNumber);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use Complex\Complex as ComplexObject;
|
||||||
use Complex\Exception as ComplexException;
|
use Complex\Exception as ComplexException;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class ComplexOperations
|
class ComplexOperations
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +38,7 @@ class ComplexOperations
|
||||||
try {
|
try {
|
||||||
return (string) (new ComplexObject($complexDividend))->divideby(new ComplexObject($complexDivisor));
|
return (string) (new ComplexObject($complexDividend))->divideby(new ComplexObject($complexDivisor));
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,7 +68,7 @@ class ComplexOperations
|
||||||
try {
|
try {
|
||||||
return (string) (new ComplexObject($complexNumber1))->subtract(new ComplexObject($complexNumber2));
|
return (string) (new ComplexObject($complexNumber1))->subtract(new ComplexObject($complexNumber2));
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,7 +96,7 @@ class ComplexOperations
|
||||||
$returnValue = $returnValue->add(new ComplexObject($complex));
|
$returnValue = $returnValue->add(new ComplexObject($complex));
|
||||||
}
|
}
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $returnValue;
|
return (string) $returnValue;
|
||||||
|
|
@ -125,7 +126,7 @@ class ComplexOperations
|
||||||
$returnValue = $returnValue->multiply(new ComplexObject($complex));
|
$returnValue = $returnValue->multiply(new ComplexObject($complex));
|
||||||
}
|
}
|
||||||
} catch (ComplexException $e) {
|
} catch (ComplexException $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) $returnValue;
|
return (string) $returnValue;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
abstract class ConvertBase
|
abstract class ConvertBase
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +15,7 @@ abstract class ConvertBase
|
||||||
{
|
{
|
||||||
if (is_bool($value)) {
|
if (is_bool($value)) {
|
||||||
if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) {
|
if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
$value = (int) $value;
|
$value = (int) $value;
|
||||||
}
|
}
|
||||||
|
|
@ -36,13 +37,13 @@ abstract class ConvertBase
|
||||||
|
|
||||||
if (is_numeric($places)) {
|
if (is_numeric($places)) {
|
||||||
if ($places < 0 || $places > 10) {
|
if ($places < 0 || $places > 10) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $places;
|
return (int) $places;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -60,7 +61,7 @@ abstract class ConvertBase
|
||||||
return substr(str_pad($value, $places, '0', STR_PAD_LEFT), -10);
|
return substr(str_pad($value, $places, '0', STR_PAD_LEFT), -10);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return substr($value, -10);
|
return substr($value, -10);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class ConvertBinary extends ConvertBase
|
class ConvertBinary extends ConvertBase
|
||||||
{
|
{
|
||||||
|
|
@ -155,7 +155,7 @@ class ConvertBinary extends ConvertBase
|
||||||
protected static function validateBinary(string $value): string
|
protected static function validateBinary(string $value): string
|
||||||
{
|
{
|
||||||
if ((strlen($value) > preg_match_all('/[01]/', $value)) || (strlen($value) > 10)) {
|
if ((strlen($value) > preg_match_all('/[01]/', $value)) || (strlen($value) > 10)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class ConvertDecimal extends ConvertBase
|
class ConvertDecimal extends ConvertBase
|
||||||
{
|
{
|
||||||
|
|
@ -61,7 +61,7 @@ class ConvertDecimal extends ConvertBase
|
||||||
|
|
||||||
$value = (int) floor((float) $value);
|
$value = (int) floor((float) $value);
|
||||||
if ($value > self::LARGEST_BINARY_IN_DECIMAL || $value < self::SMALLEST_BINARY_IN_DECIMAL) {
|
if ($value > self::LARGEST_BINARY_IN_DECIMAL || $value < self::SMALLEST_BINARY_IN_DECIMAL) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = decbin($value);
|
$r = decbin($value);
|
||||||
|
|
@ -118,7 +118,7 @@ class ConvertDecimal extends ConvertBase
|
||||||
|
|
||||||
$value = floor((float) $value);
|
$value = floor((float) $value);
|
||||||
if ($value > self::LARGEST_HEX_IN_DECIMAL || $value < self::SMALLEST_HEX_IN_DECIMAL) {
|
if ($value > self::LARGEST_HEX_IN_DECIMAL || $value < self::SMALLEST_HEX_IN_DECIMAL) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
$r = strtoupper(dechex((int) $value));
|
$r = strtoupper(dechex((int) $value));
|
||||||
$r = self::hex32bit($value, $r);
|
$r = self::hex32bit($value, $r);
|
||||||
|
|
@ -194,7 +194,7 @@ class ConvertDecimal extends ConvertBase
|
||||||
|
|
||||||
$value = (int) floor((float) $value);
|
$value = (int) floor((float) $value);
|
||||||
if ($value > self::LARGEST_OCTAL_IN_DECIMAL || $value < self::SMALLEST_OCTAL_IN_DECIMAL) {
|
if ($value > self::LARGEST_OCTAL_IN_DECIMAL || $value < self::SMALLEST_OCTAL_IN_DECIMAL) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
$r = decoct($value);
|
$r = decoct($value);
|
||||||
$r = substr($r, -10);
|
$r = substr($r, -10);
|
||||||
|
|
@ -205,7 +205,7 @@ class ConvertDecimal extends ConvertBase
|
||||||
protected static function validateDecimal(string $value): string
|
protected static function validateDecimal(string $value): string
|
||||||
{
|
{
|
||||||
if (strlen($value) > preg_match_all('/[-0123456789.]/', $value)) {
|
if (strlen($value) > preg_match_all('/[-0123456789.]/', $value)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class ConvertHex extends ConvertBase
|
class ConvertHex extends ConvertBase
|
||||||
{
|
{
|
||||||
|
|
@ -92,7 +92,7 @@ class ConvertHex extends ConvertBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($value) > 10) {
|
if (strlen($value) > 10) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$binX = '';
|
$binX = '';
|
||||||
|
|
@ -167,7 +167,7 @@ class ConvertHex extends ConvertBase
|
||||||
protected static function validateHex(string $value): string
|
protected static function validateHex(string $value): string
|
||||||
{
|
{
|
||||||
if (strlen($value) > preg_match_all('/[0123456789ABCDEF]/', $value)) {
|
if (strlen($value) > preg_match_all('/[0123456789ABCDEF]/', $value)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class ConvertOctal extends ConvertBase
|
class ConvertOctal extends ConvertBase
|
||||||
{
|
{
|
||||||
|
|
@ -166,7 +166,7 @@ class ConvertOctal extends ConvertBase
|
||||||
{
|
{
|
||||||
$numDigits = (int) preg_match_all('/[01234567]/', $value);
|
$numDigits = (int) preg_match_all('/[01234567]/', $value);
|
||||||
if (strlen($value) > $numDigits || $numDigits > 10) {
|
if (strlen($value) > $numDigits || $numDigits > 10) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class ConvertUOM
|
class ConvertUOM
|
||||||
{
|
{
|
||||||
|
|
@ -539,18 +539,18 @@ class ConvertUOM
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
[$fromUOM, $fromCategory, $fromMultiplier] = self::getUOMDetails($fromUOM);
|
[$fromUOM, $fromCategory, $fromMultiplier] = self::getUOMDetails($fromUOM);
|
||||||
[$toUOM, $toCategory, $toMultiplier] = self::getUOMDetails($toUOM);
|
[$toUOM, $toCategory, $toMultiplier] = self::getUOMDetails($toUOM);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fromCategory !== $toCategory) {
|
if ($fromCategory !== $toCategory) {
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @var float $value
|
// @var float $value
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class EngineeringValidations
|
class EngineeringValidations
|
||||||
{
|
{
|
||||||
|
|
@ -13,7 +13,7 @@ class EngineeringValidations
|
||||||
public static function validateFloat($value): float
|
public static function validateFloat($value): float
|
||||||
{
|
{
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (float) $value;
|
return (float) $value;
|
||||||
|
|
@ -25,7 +25,7 @@ class EngineeringValidations
|
||||||
public static function validateInt($value): int
|
public static function validateInt($value): int
|
||||||
{
|
{
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) floor((float) $value);
|
return (int) floor((float) $value);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Erf
|
class Erf
|
||||||
{
|
{
|
||||||
|
|
@ -49,7 +50,7 @@ class Erf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class ErfC
|
class ErfC
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +40,7 @@ class ErfC
|
||||||
return self::erfcValue($value);
|
return self::erfcValue($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\FinancialValidations;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\FinancialValidations;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class CashFlowValidations extends FinancialValidations
|
class CashFlowValidations extends FinancialValidations
|
||||||
{
|
{
|
||||||
|
|
@ -29,7 +29,7 @@ class CashFlowValidations extends FinancialValidations
|
||||||
$type !== FinancialConstants::PAYMENT_END_OF_PERIOD &&
|
$type !== FinancialConstants::PAYMENT_END_OF_PERIOD &&
|
||||||
$type !== FinancialConstants::PAYMENT_BEGINNING_OF_PERIOD
|
$type !== FinancialConstants::PAYMENT_BEGINNING_OF_PERIOD
|
||||||
) {
|
) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rate;
|
return $rate;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Periodic
|
class Periodic
|
||||||
{
|
{
|
||||||
|
|
@ -94,7 +95,7 @@ class Periodic
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($numberOfPeriods < 0) {
|
if ($numberOfPeriods < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::calculatePresentValue($rate, $numberOfPeriods, $payment, $futureValue, $type);
|
return self::calculatePresentValue($rate, $numberOfPeriods, $payment, $futureValue, $type);
|
||||||
|
|
@ -138,7 +139,7 @@ class Periodic
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($payment == 0.0) {
|
if ($payment == 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::calculatePeriods($rate, $payment, $presentValue, $futureValue, $type);
|
return self::calculatePeriods($rate, $payment, $presentValue, $futureValue, $type);
|
||||||
|
|
@ -187,7 +188,7 @@ class Periodic
|
||||||
) {
|
) {
|
||||||
if ($rate != 0.0) {
|
if ($rate != 0.0) {
|
||||||
if ($presentValue == 0.0) {
|
if ($presentValue == 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return log(($payment * (1 + $rate * $type) / $rate - $futureValue) /
|
return log(($payment * (1 + $rate * $type) / $rate - $futureValue) /
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Cumulative
|
class Cumulative
|
||||||
{
|
{
|
||||||
|
|
@ -57,7 +58,7 @@ class Cumulative
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($start < 1 || $start > $end) {
|
if ($start < 1 || $start > $end) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate
|
// Calculate
|
||||||
|
|
@ -122,7 +123,7 @@ class Cumulative
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($start < 1 || $start > $end) {
|
if ($start < 1 || $start > $end) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate
|
// Calculate
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Interest
|
class Interest
|
||||||
{
|
{
|
||||||
|
|
@ -59,7 +60,7 @@ class Interest
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($period <= 0 || $period > $numberOfPeriods) {
|
if ($period <= 0 || $period > $numberOfPeriods) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate
|
// Calculate
|
||||||
|
|
@ -106,7 +107,7 @@ class Interest
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($period <= 0 || $period > $numberOfPeriods) {
|
if ($period <= 0 || $period > $numberOfPeriods) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return value
|
// Return value
|
||||||
|
|
@ -193,13 +194,13 @@ class Interest
|
||||||
$rate = $rate1;
|
$rate = $rate1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $close ? $rate : Functions::NAN();
|
return $close ? $rate : ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function rateNextGuess($rate, $numberOfPeriods, $payment, $presentValue, $futureValue, $type)
|
private static function rateNextGuess($rate, $numberOfPeriods, $payment, $presentValue, $futureValue, $type)
|
||||||
{
|
{
|
||||||
if ($rate == 0.0) {
|
if ($rate == 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
$tt1 = ($rate + 1) ** $numberOfPeriods;
|
$tt1 = ($rate + 1) ** $numberOfPeriods;
|
||||||
$tt2 = ($rate + 1) ** ($numberOfPeriods - 1);
|
$tt2 = ($rate + 1) ** ($numberOfPeriods - 1);
|
||||||
|
|
@ -208,7 +209,7 @@ class Interest
|
||||||
* ($rate * $type + 1) / ($rate * $rate) + $numberOfPeriods
|
* ($rate * $type + 1) / ($rate * $rate) + $numberOfPeriods
|
||||||
* $payment * $tt2 * ($rate * $type + 1) / $rate + $payment * ($tt1 - 1) * $type / $rate;
|
* $payment * $tt2 * ($rate * $type + 1) / $rate + $payment * ($tt1 - 1) * $type / $rate;
|
||||||
if ($denominator == 0) {
|
if ($denominator == 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $numerator / $denominator;
|
return $numerator / $denominator;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Payments
|
class Payments
|
||||||
{
|
{
|
||||||
|
|
@ -97,7 +98,7 @@ class Payments
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($period <= 0 || $period > $numberOfPeriods) {
|
if ($period <= 0 || $period > $numberOfPeriods) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate
|
// Calculate
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Single
|
class Single
|
||||||
{
|
{
|
||||||
|
|
@ -67,7 +68,7 @@ class Single
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($rate <= 0.0 || $presentValue <= 0.0 || $futureValue <= 0.0) {
|
if ($rate <= 0.0 || $presentValue <= 0.0 || $futureValue <= 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (log($futureValue) - log($presentValue)) / log(1 + $rate);
|
return (log($futureValue) - log($presentValue)) / log(1 + $rate);
|
||||||
|
|
@ -100,7 +101,7 @@ class Single
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if ($periods <= 0.0 || $presentValue <= 0.0 || $futureValue < 0.0) {
|
if ($periods <= 0.0 || $presentValue <= 0.0 || $futureValue < 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($futureValue / $presentValue) ** (1 / $periods) - 1;
|
return ($futureValue / $presentValue) ** (1 / $periods) - 1;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Variable;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class NonPeriodic
|
class NonPeriodic
|
||||||
{
|
{
|
||||||
|
|
@ -41,7 +42,7 @@ class NonPeriodic
|
||||||
// create an initial range, with a root somewhere between 0 and guess
|
// create an initial range, with a root somewhere between 0 and guess
|
||||||
$guess = Functions::flattenSingleValue($guess) ?? self::DEFAULT_GUESS;
|
$guess = Functions::flattenSingleValue($guess) ?? self::DEFAULT_GUESS;
|
||||||
if (!is_numeric($guess)) {
|
if (!is_numeric($guess)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
$guess = ($guess + 0.0) ?: self::DEFAULT_GUESS;
|
$guess = ($guess + 0.0) ?: self::DEFAULT_GUESS;
|
||||||
$x1 = 0.0;
|
$x1 = 0.0;
|
||||||
|
|
@ -68,7 +69,7 @@ class NonPeriodic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::xirrPart3($values, $dates, $x1, $x2);
|
return self::xirrPart3($values, $dates, $x1, $x2);
|
||||||
|
|
@ -117,10 +118,10 @@ class NonPeriodic
|
||||||
$valuesIsArray = count($values) > 1;
|
$valuesIsArray = count($values) > 1;
|
||||||
$datesIsArray = count($dates) > 1;
|
$datesIsArray = count($dates) > 1;
|
||||||
if (!$valuesIsArray && !$datesIsArray) {
|
if (!$valuesIsArray && !$datesIsArray) {
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
if (count($values) != count($dates)) {
|
if (count($values) != count($dates)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$datesCount = count($dates);
|
$datesCount = count($dates);
|
||||||
|
|
@ -143,7 +144,7 @@ class NonPeriodic
|
||||||
for ($i = 0; $i < $valCount; ++$i) {
|
for ($i = 0; $i < $valCount; ++$i) {
|
||||||
$fld = $values[$i];
|
$fld = $values[$i];
|
||||||
if (!is_numeric($fld)) {
|
if (!is_numeric($fld)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
} elseif ($fld > 0) {
|
} elseif ($fld > 0) {
|
||||||
$foundpos = true;
|
$foundpos = true;
|
||||||
} elseif ($fld < 0) {
|
} elseif ($fld < 0) {
|
||||||
|
|
@ -151,7 +152,7 @@ class NonPeriodic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!self::bothNegAndPos($foundneg, $foundpos)) {
|
if (!self::bothNegAndPos($foundneg, $foundpos)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -171,7 +172,7 @@ class NonPeriodic
|
||||||
$dx = $x1 - $x2;
|
$dx = $x1 - $x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rslt = Functions::VALUE();
|
$rslt = ExcelError::VALUE();
|
||||||
for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) {
|
for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) {
|
||||||
$dx *= 0.5;
|
$dx *= 0.5;
|
||||||
$x_mid = $rtb + $dx;
|
$x_mid = $rtb + $dx;
|
||||||
|
|
@ -213,7 +214,7 @@ class NonPeriodic
|
||||||
$xnpv = 0.0;
|
$xnpv = 0.0;
|
||||||
for ($i = 0; $i < $valCount; ++$i) {
|
for ($i = 0; $i < $valCount; ++$i) {
|
||||||
if (!is_numeric($values[$i])) {
|
if (!is_numeric($values[$i])) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -222,7 +223,7 @@ class NonPeriodic
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
if ($date0 > $datei) {
|
if ($date0 > $datei) {
|
||||||
$dif = $ordered ? Functions::NAN() : -((int) DateTimeExcel\Difference::interval($datei, $date0, 'd'));
|
$dif = $ordered ? ExcelError::NAN() : -((int) DateTimeExcel\Difference::interval($datei, $date0, 'd'));
|
||||||
} else {
|
} else {
|
||||||
$dif = DateTimeExcel\Difference::interval($date0, $datei, 'd');
|
$dif = DateTimeExcel\Difference::interval($date0, $datei, 'd');
|
||||||
}
|
}
|
||||||
|
|
@ -236,7 +237,7 @@ class NonPeriodic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_finite($xnpv) ? $xnpv : Functions::VALUE();
|
return is_finite($xnpv) ? $xnpv : ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -245,14 +246,14 @@ class NonPeriodic
|
||||||
private static function validateXnpv($rate, array $values, array $dates): void
|
private static function validateXnpv($rate, array $values, array $dates): void
|
||||||
{
|
{
|
||||||
if (!is_numeric($rate)) {
|
if (!is_numeric($rate)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
$valCount = count($values);
|
$valCount = count($values);
|
||||||
if ($valCount != count($dates)) {
|
if ($valCount != count($dates)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
if ($valCount > 1 && ((min($values) > 0) || (max($values) < 0))) {
|
if ($valCount > 1 && ((min($values) > 0) || (max($values) < 0))) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Variable;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Variable;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Periodic
|
class Periodic
|
||||||
{
|
{
|
||||||
|
|
@ -33,7 +34,7 @@ class Periodic
|
||||||
public static function rate($values, $guess = 0.1)
|
public static function rate($values, $guess = 0.1)
|
||||||
{
|
{
|
||||||
if (!is_array($values)) {
|
if (!is_array($values)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
$values = Functions::flattenArray($values);
|
$values = Functions::flattenArray($values);
|
||||||
$guess = Functions::flattenSingleValue($guess);
|
$guess = Functions::flattenSingleValue($guess);
|
||||||
|
|
@ -54,7 +55,7 @@ class Periodic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (($f1 * $f2) > 0.0) {
|
if (($f1 * $f2) > 0.0) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
$f = self::presentValue($x1, $values);
|
$f = self::presentValue($x1, $values);
|
||||||
|
|
@ -78,7 +79,7 @@ class Periodic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -101,7 +102,7 @@ class Periodic
|
||||||
public static function modifiedRate($values, $financeRate, $reinvestmentRate)
|
public static function modifiedRate($values, $financeRate, $reinvestmentRate)
|
||||||
{
|
{
|
||||||
if (!is_array($values)) {
|
if (!is_array($values)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
$values = Functions::flattenArray($values);
|
$values = Functions::flattenArray($values);
|
||||||
$financeRate = Functions::flattenSingleValue($financeRate);
|
$financeRate = Functions::flattenSingleValue($financeRate);
|
||||||
|
|
@ -121,13 +122,13 @@ class Periodic
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($npvNeg === 0.0) || ($npvPos === 0.0) || ($reinvestmentRate <= -1.0)) {
|
if (($npvNeg === 0.0) || ($npvPos === 0.0) || ($reinvestmentRate <= -1.0)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
$mirr = ((-$npvPos * $rr ** $n)
|
$mirr = ((-$npvPos * $rr ** $n)
|
||||||
/ ($npvNeg * ($rr))) ** (1.0 / ($n - 1)) - 1.0;
|
/ ($npvNeg * ($rr))) ** (1.0 / ($n - 1)) - 1.0;
|
||||||
|
|
||||||
return is_finite($mirr) ? $mirr : Functions::VALUE();
|
return is_finite($mirr) ? $mirr : ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
|
||||||
class Coupons
|
class Coupons
|
||||||
|
|
@ -66,7 +67,7 @@ class Coupons
|
||||||
|
|
||||||
$daysPerYear = Helpers::daysPerYear(Functions::scalar(DateTimeExcel\DateParts::year($settlement)), $basis);
|
$daysPerYear = Helpers::daysPerYear(Functions::scalar(DateTimeExcel\DateParts::year($settlement)), $basis);
|
||||||
if (is_string($daysPerYear)) {
|
if (is_string($daysPerYear)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
$prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS);
|
$prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS);
|
||||||
|
|
||||||
|
|
@ -409,7 +410,7 @@ class Coupons
|
||||||
private static function validateCouponPeriod(float $settlement, float $maturity): void
|
private static function validateCouponPeriod(float $settlement, float $maturity): void
|
||||||
{
|
{
|
||||||
if ($settlement >= $maturity) {
|
if ($settlement >= $maturity) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Depreciation
|
class Depreciation
|
||||||
{
|
{
|
||||||
|
|
@ -117,7 +118,7 @@ class Depreciation
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($period > $life) {
|
if ($period > $life) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through each period calculating the depreciation
|
// Loop through each period calculating the depreciation
|
||||||
|
|
@ -161,7 +162,7 @@ class Depreciation
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($life === 0.0) {
|
if ($life === 0.0) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($cost - $salvage) / $life;
|
return ($cost - $salvage) / $life;
|
||||||
|
|
@ -196,7 +197,7 @@ class Depreciation
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($period > $life) {
|
if ($period > $life) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$syd = (($cost - $salvage) * ($life - $period + 1) * 2) / ($life * ($life + 1));
|
$syd = (($cost - $salvage) * ($life - $period + 1) * 2) / ($life * ($life + 1));
|
||||||
|
|
@ -208,7 +209,7 @@ class Depreciation
|
||||||
{
|
{
|
||||||
$cost = FinancialValidations::validateFloat($cost);
|
$cost = FinancialValidations::validateFloat($cost);
|
||||||
if ($cost < 0.0 && $negativeValueAllowed === false) {
|
if ($cost < 0.0 && $negativeValueAllowed === false) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cost;
|
return $cost;
|
||||||
|
|
@ -218,7 +219,7 @@ class Depreciation
|
||||||
{
|
{
|
||||||
$salvage = FinancialValidations::validateFloat($salvage);
|
$salvage = FinancialValidations::validateFloat($salvage);
|
||||||
if ($salvage < 0.0 && $negativeValueAllowed === false) {
|
if ($salvage < 0.0 && $negativeValueAllowed === false) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $salvage;
|
return $salvage;
|
||||||
|
|
@ -228,7 +229,7 @@ class Depreciation
|
||||||
{
|
{
|
||||||
$life = FinancialValidations::validateFloat($life);
|
$life = FinancialValidations::validateFloat($life);
|
||||||
if ($life < 0.0 && $negativeValueAllowed === false) {
|
if ($life < 0.0 && $negativeValueAllowed === false) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $life;
|
return $life;
|
||||||
|
|
@ -238,7 +239,7 @@ class Depreciation
|
||||||
{
|
{
|
||||||
$period = FinancialValidations::validateFloat($period);
|
$period = FinancialValidations::validateFloat($period);
|
||||||
if ($period <= 0.0 && $negativeValueAllowed === false) {
|
if ($period <= 0.0 && $negativeValueAllowed === false) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $period;
|
return $period;
|
||||||
|
|
@ -248,7 +249,7 @@ class Depreciation
|
||||||
{
|
{
|
||||||
$month = FinancialValidations::validateInt($month);
|
$month = FinancialValidations::validateInt($month);
|
||||||
if ($month < 1) {
|
if ($month < 1) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $month;
|
return $month;
|
||||||
|
|
@ -258,7 +259,7 @@ class Depreciation
|
||||||
{
|
{
|
||||||
$factor = FinancialValidations::validateFloat($factor);
|
$factor = FinancialValidations::validateFloat($factor);
|
||||||
if ($factor <= 0.0) {
|
if ($factor <= 0.0) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $factor;
|
return $factor;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\TextData\Format;
|
use PhpOffice\PhpSpreadsheet\Calculation\TextData\Format;
|
||||||
|
|
||||||
class Dollar
|
class Dollar
|
||||||
|
|
@ -67,10 +68,10 @@ class Dollar
|
||||||
|
|
||||||
// Additional parameter validations
|
// Additional parameter validations
|
||||||
if ($fraction < 0) {
|
if ($fraction < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
if ($fraction == 0) {
|
if ($fraction == 0) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
$dollars = ($fractionalDollar < 0) ? ceil($fractionalDollar) : floor($fractionalDollar);
|
$dollars = ($fractionalDollar < 0) ? ceil($fractionalDollar) : floor($fractionalDollar);
|
||||||
|
|
@ -115,10 +116,10 @@ class Dollar
|
||||||
|
|
||||||
// Additional parameter validations
|
// Additional parameter validations
|
||||||
if ($fraction < 0) {
|
if ($fraction < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
if ($fraction == 0) {
|
if ($fraction == 0) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
$dollars = ($decimalDollar < 0.0) ? ceil($decimalDollar) : floor($decimalDollar);
|
$dollars = ($decimalDollar < 0.0) ? ceil($decimalDollar) : floor($decimalDollar);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class FinancialValidations
|
class FinancialValidations
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +39,7 @@ class FinancialValidations
|
||||||
public static function validateFloat($value): float
|
public static function validateFloat($value): float
|
||||||
{
|
{
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (float) $value;
|
return (float) $value;
|
||||||
|
|
@ -51,7 +51,7 @@ class FinancialValidations
|
||||||
public static function validateInt($value): int
|
public static function validateInt($value): int
|
||||||
{
|
{
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) floor((float) $value);
|
return (int) floor((float) $value);
|
||||||
|
|
@ -64,7 +64,7 @@ class FinancialValidations
|
||||||
{
|
{
|
||||||
$rate = self::validateFloat($rate);
|
$rate = self::validateFloat($rate);
|
||||||
if ($rate < 0.0) {
|
if ($rate < 0.0) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rate;
|
return $rate;
|
||||||
|
|
@ -81,7 +81,7 @@ class FinancialValidations
|
||||||
($frequency !== FinancialConstants::FREQUENCY_SEMI_ANNUAL) &&
|
($frequency !== FinancialConstants::FREQUENCY_SEMI_ANNUAL) &&
|
||||||
($frequency !== FinancialConstants::FREQUENCY_QUARTERLY)
|
($frequency !== FinancialConstants::FREQUENCY_QUARTERLY)
|
||||||
) {
|
) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $frequency;
|
return $frequency;
|
||||||
|
|
@ -93,12 +93,12 @@ class FinancialValidations
|
||||||
public static function validateBasis($basis): int
|
public static function validateBasis($basis): int
|
||||||
{
|
{
|
||||||
if (!is_numeric($basis)) {
|
if (!is_numeric($basis)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
$basis = (int) $basis;
|
$basis = (int) $basis;
|
||||||
if (($basis < 0) || ($basis > 4)) {
|
if (($basis < 0) || ($basis > 4)) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $basis;
|
return $basis;
|
||||||
|
|
@ -111,7 +111,7 @@ class FinancialValidations
|
||||||
{
|
{
|
||||||
$price = self::validateFloat($price);
|
$price = self::validateFloat($price);
|
||||||
if ($price < 0.0) {
|
if ($price < 0.0) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $price;
|
return $price;
|
||||||
|
|
@ -124,7 +124,7 @@ class FinancialValidations
|
||||||
{
|
{
|
||||||
$parValue = self::validateFloat($parValue);
|
$parValue = self::validateFloat($parValue);
|
||||||
if ($parValue < 0.0) {
|
if ($parValue < 0.0) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $parValue;
|
return $parValue;
|
||||||
|
|
@ -137,7 +137,7 @@ class FinancialValidations
|
||||||
{
|
{
|
||||||
$yield = self::validateFloat($yield);
|
$yield = self::validateFloat($yield);
|
||||||
if ($yield < 0.0) {
|
if ($yield < 0.0) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $yield;
|
return $yield;
|
||||||
|
|
@ -150,7 +150,7 @@ class FinancialValidations
|
||||||
{
|
{
|
||||||
$discount = self::validateFloat($discount);
|
$discount = self::validateFloat($discount);
|
||||||
if ($discount <= 0.0) {
|
if ($discount <= 0.0) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $discount;
|
return $discount;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Helpers
|
class Helpers
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +27,7 @@ class Helpers
|
||||||
public static function daysPerYear($year, $basis = 0)
|
public static function daysPerYear($year, $basis = 0)
|
||||||
{
|
{
|
||||||
if (!is_numeric($basis)) {
|
if (!is_numeric($basis)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($basis) {
|
switch ($basis) {
|
||||||
|
|
@ -41,7 +41,7 @@ class Helpers
|
||||||
return (DateTimeExcel\Helpers::isLeapYear($year)) ? 366 : 365;
|
return (DateTimeExcel\Helpers::isLeapYear($year)) ? 366 : 365;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class InterestRate
|
class InterestRate
|
||||||
{
|
{
|
||||||
|
|
@ -34,7 +35,7 @@ class InterestRate
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($nominalRate <= 0 || $periodsPerYear < 1) {
|
if ($nominalRate <= 0 || $periodsPerYear < 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((1 + $nominalRate / $periodsPerYear) ** $periodsPerYear) - 1;
|
return ((1 + $nominalRate / $periodsPerYear) ** $periodsPerYear) - 1;
|
||||||
|
|
@ -63,7 +64,7 @@ class InterestRate
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($effectiveRate <= 0 || $periodsPerYear < 1) {
|
if ($effectiveRate <= 0 || $periodsPerYear < 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate
|
// Calculate
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstan
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Coupons;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Coupons;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Price
|
class Price
|
||||||
{
|
{
|
||||||
|
|
@ -270,7 +271,7 @@ class Price
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($investment <= 0) {
|
if ($investment <= 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
|
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
|
||||||
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
|
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Rates
|
class Rates
|
||||||
{
|
{
|
||||||
|
|
@ -60,7 +61,7 @@ class Rates
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($price <= 0.0) {
|
if ($price <= 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
|
$daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
|
||||||
|
|
@ -123,7 +124,7 @@ class Rates
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($investment <= 0) {
|
if ($investment <= 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
|
$daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\FinancialValidations;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\FinancialValidations;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class SecurityValidations extends FinancialValidations
|
class SecurityValidations extends FinancialValidations
|
||||||
{
|
{
|
||||||
|
|
@ -23,7 +23,7 @@ class SecurityValidations extends FinancialValidations
|
||||||
public static function validateSecurityPeriod($settlement, $maturity): void
|
public static function validateSecurityPeriod($settlement, $maturity): void
|
||||||
{
|
{
|
||||||
if ($settlement >= $maturity) {
|
if ($settlement >= $maturity) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ class SecurityValidations extends FinancialValidations
|
||||||
{
|
{
|
||||||
$redemption = self::validateFloat($redemption);
|
$redemption = self::validateFloat($redemption);
|
||||||
if ($redemption <= 0.0) {
|
if ($redemption <= 0.0) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $redemption;
|
return $redemption;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class TreasuryBill
|
class TreasuryBill
|
||||||
{
|
{
|
||||||
|
|
@ -38,7 +39,7 @@ class TreasuryBill
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($discount <= 0) {
|
if ($discount <= 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$daysBetweenSettlementAndMaturity = $maturity - $settlement;
|
$daysBetweenSettlementAndMaturity = $maturity - $settlement;
|
||||||
|
|
@ -48,7 +49,7 @@ class TreasuryBill
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
|
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (365 * $discount) / (360 - $discount * $daysBetweenSettlementAndMaturity);
|
return (365 * $discount) / (360 - $discount * $daysBetweenSettlementAndMaturity);
|
||||||
|
|
@ -83,7 +84,7 @@ class TreasuryBill
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($discount <= 0) {
|
if ($discount <= 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$daysBetweenSettlementAndMaturity = $maturity - $settlement;
|
$daysBetweenSettlementAndMaturity = $maturity - $settlement;
|
||||||
|
|
@ -93,12 +94,12 @@ class TreasuryBill
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
|
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$price = 100 * (1 - (($discount * $daysBetweenSettlementAndMaturity) / 360));
|
$price = 100 * (1 - (($discount * $daysBetweenSettlementAndMaturity) / 360));
|
||||||
if ($price < 0.0) {
|
if ($price < 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $price;
|
return $price;
|
||||||
|
|
@ -139,7 +140,7 @@ class TreasuryBill
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
|
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((100 - $price) / $price) * (360 / $daysBetweenSettlementAndMaturity);
|
return ((100 - $price) / $price) * (360 / $daysBetweenSettlementAndMaturity);
|
||||||
|
|
|
||||||
|
|
@ -41,30 +41,14 @@ class Functions
|
||||||
*/
|
*/
|
||||||
protected static $returnDateType = self::RETURNDATE_EXCEL;
|
protected static $returnDateType = self::RETURNDATE_EXCEL;
|
||||||
|
|
||||||
/**
|
|
||||||
* List of error codes.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected static $errorCodes = [
|
|
||||||
'null' => '#NULL!',
|
|
||||||
'divisionbyzero' => '#DIV/0!',
|
|
||||||
'value' => '#VALUE!',
|
|
||||||
'reference' => '#REF!',
|
|
||||||
'name' => '#NAME?',
|
|
||||||
'num' => '#NUM!',
|
|
||||||
'na' => '#N/A',
|
|
||||||
'gettingdata' => '#GETTING_DATA',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Compatibility Mode.
|
* Set the Compatibility Mode.
|
||||||
*
|
*
|
||||||
* @param string $compatibilityMode Compatibility Mode
|
* @param string $compatibilityMode Compatibility Mode
|
||||||
* Permitted values are:
|
* Permitted values are:
|
||||||
* Functions::COMPATIBILITY_EXCEL 'Excel'
|
* Functions::COMPATIBILITY_EXCEL 'Excel'
|
||||||
* Functions::COMPATIBILITY_GNUMERIC 'Gnumeric'
|
* Functions::COMPATIBILITY_GNUMERIC 'Gnumeric'
|
||||||
* Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc'
|
* Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc'
|
||||||
*
|
*
|
||||||
* @return bool (Success or Failure)
|
* @return bool (Success or Failure)
|
||||||
*/
|
*/
|
||||||
|
|
@ -87,10 +71,10 @@ class Functions
|
||||||
* Return the current Compatibility Mode.
|
* Return the current Compatibility Mode.
|
||||||
*
|
*
|
||||||
* @return string Compatibility Mode
|
* @return string Compatibility Mode
|
||||||
* Possible Return values are:
|
* Possible Return values are:
|
||||||
* Functions::COMPATIBILITY_EXCEL 'Excel'
|
* Functions::COMPATIBILITY_EXCEL 'Excel'
|
||||||
* Functions::COMPATIBILITY_GNUMERIC 'Gnumeric'
|
* Functions::COMPATIBILITY_GNUMERIC 'Gnumeric'
|
||||||
* Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc'
|
* Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc'
|
||||||
*/
|
*/
|
||||||
public static function getCompatibilityMode()
|
public static function getCompatibilityMode()
|
||||||
{
|
{
|
||||||
|
|
@ -98,13 +82,13 @@ class Functions
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object).
|
* Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric or PHP DateTime Object).
|
||||||
*
|
*
|
||||||
* @param string $returnDateType Return Date Format
|
* @param string $returnDateType Return Date Format
|
||||||
* Permitted values are:
|
* Permitted values are:
|
||||||
* Functions::RETURNDATE_UNIX_TIMESTAMP 'P'
|
* Functions::RETURNDATE_UNIX_TIMESTAMP 'P'
|
||||||
* Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O'
|
* Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O'
|
||||||
* Functions::RETURNDATE_EXCEL 'E'
|
* Functions::RETURNDATE_EXCEL 'E'
|
||||||
*
|
*
|
||||||
* @return bool Success or failure
|
* @return bool Success or failure
|
||||||
*/
|
*/
|
||||||
|
|
@ -127,10 +111,10 @@ class Functions
|
||||||
* Return the current Return Date Format for functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object).
|
* Return the current Return Date Format for functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object).
|
||||||
*
|
*
|
||||||
* @return string Return Date Format
|
* @return string Return Date Format
|
||||||
* Possible Return values are:
|
* Possible Return values are:
|
||||||
* Functions::RETURNDATE_UNIX_TIMESTAMP 'P'
|
* Functions::RETURNDATE_UNIX_TIMESTAMP 'P'
|
||||||
* Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O'
|
* Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O'
|
||||||
* Functions::RETURNDATE_EXCEL 'E'
|
* Functions::RETURNDATE_EXCEL ' 'E'
|
||||||
*/
|
*/
|
||||||
public static function getReturnDateType()
|
public static function getReturnDateType()
|
||||||
{
|
{
|
||||||
|
|
@ -147,90 +131,21 @@ class Functions
|
||||||
return '#Not Yet Implemented';
|
return '#Not Yet Implemented';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DIV0.
|
|
||||||
*
|
|
||||||
* @return string #Not Yet Implemented
|
|
||||||
*/
|
|
||||||
public static function DIV0()
|
|
||||||
{
|
|
||||||
return self::$errorCodes['divisionbyzero'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NA.
|
|
||||||
*
|
|
||||||
* Excel Function:
|
|
||||||
* =NA()
|
|
||||||
*
|
|
||||||
* Returns the error value #N/A
|
|
||||||
* #N/A is the error value that means "no value is available."
|
|
||||||
*
|
|
||||||
* @return string #N/A!
|
|
||||||
*/
|
|
||||||
public static function NA()
|
|
||||||
{
|
|
||||||
return self::$errorCodes['na'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NaN.
|
|
||||||
*
|
|
||||||
* Returns the error value #NUM!
|
|
||||||
*
|
|
||||||
* @return string #NUM!
|
|
||||||
*/
|
|
||||||
public static function NAN()
|
|
||||||
{
|
|
||||||
return self::$errorCodes['num'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NAME.
|
|
||||||
*
|
|
||||||
* Returns the error value #NAME?
|
|
||||||
*
|
|
||||||
* @return string #NAME?
|
|
||||||
*/
|
|
||||||
public static function NAME()
|
|
||||||
{
|
|
||||||
return self::$errorCodes['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* REF.
|
|
||||||
*
|
|
||||||
* Returns the error value #REF!
|
|
||||||
*
|
|
||||||
* @return string #REF!
|
|
||||||
*/
|
|
||||||
public static function REF()
|
|
||||||
{
|
|
||||||
return self::$errorCodes['reference'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NULL.
|
* NULL.
|
||||||
*
|
*
|
||||||
* Returns the error value #NULL!
|
* Returns the error value #NULL!
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
* @return string #NULL!
|
* @return string #NULL!
|
||||||
|
*
|
||||||
|
*@see Information\ExcelError::null()
|
||||||
|
* Use the null() method in the Information\Error class instead
|
||||||
*/
|
*/
|
||||||
public static function null()
|
public static function null()
|
||||||
{
|
{
|
||||||
return self::$errorCodes['null'];
|
return Information\ExcelError::null();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* VALUE.
|
|
||||||
*
|
|
||||||
* Returns the error value #VALUE!
|
|
||||||
*
|
|
||||||
* @return string #VALUE!
|
|
||||||
*/
|
|
||||||
public static function VALUE()
|
|
||||||
{
|
|
||||||
return self::$errorCodes['value'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isMatrixValue($idx)
|
public static function isMatrixValue($idx)
|
||||||
|
|
@ -240,7 +155,7 @@ class Functions
|
||||||
|
|
||||||
public static function isValue($idx)
|
public static function isValue($idx)
|
||||||
{
|
{
|
||||||
return substr_count($idx, '.') == 0;
|
return substr_count($idx, '.') === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isCellValue($idx)
|
public static function isCellValue($idx)
|
||||||
|
|
@ -300,26 +215,125 @@ class Functions
|
||||||
return $operand;
|
return $operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NaN.
|
||||||
|
*
|
||||||
|
* Returns the error value #NUM!
|
||||||
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @return string #NUM!
|
||||||
|
*
|
||||||
|
* @see Information\ExcelError::NAN()
|
||||||
|
* Use the NAN() method in the Information\Error class instead
|
||||||
|
*/
|
||||||
|
public static function NAN()
|
||||||
|
{
|
||||||
|
return Information\ExcelError::NAN();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REF.
|
||||||
|
*
|
||||||
|
* Returns the error value #REF!
|
||||||
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @return string #REF!
|
||||||
|
*
|
||||||
|
* @see Information\ExcelError::REF()
|
||||||
|
* Use the REF() method in the Information\Error class instead
|
||||||
|
*/
|
||||||
|
public static function REF()
|
||||||
|
{
|
||||||
|
return Information\ExcelError::REF();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NA.
|
||||||
|
*
|
||||||
|
* Excel Function:
|
||||||
|
* =NA()
|
||||||
|
*
|
||||||
|
* Returns the error value #N/A
|
||||||
|
* #N/A is the error value that means "no value is available."
|
||||||
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @return string #N/A!
|
||||||
|
*
|
||||||
|
* @see Information\ExcelError::NA()
|
||||||
|
* Use the NA() method in the Information\Error class instead
|
||||||
|
*/
|
||||||
|
public static function NA()
|
||||||
|
{
|
||||||
|
return Information\ExcelError::NA();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VALUE.
|
||||||
|
*
|
||||||
|
* Returns the error value #VALUE!
|
||||||
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @return string #VALUE!
|
||||||
|
*
|
||||||
|
* @see Information\ExcelError::VALUE()
|
||||||
|
* Use the VALUE() method in the Information\Error class instead
|
||||||
|
*/
|
||||||
|
public static function VALUE()
|
||||||
|
{
|
||||||
|
return Information\ExcelError::VALUE();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NAME.
|
||||||
|
*
|
||||||
|
* Returns the error value #NAME?
|
||||||
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @return string #NAME?
|
||||||
|
*
|
||||||
|
* @see Information\ExcelError::NAME()
|
||||||
|
* Use the NAME() method in the Information\Error class instead
|
||||||
|
*/
|
||||||
|
public static function NAME()
|
||||||
|
{
|
||||||
|
return Information\ExcelError::NAME();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DIV0.
|
||||||
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @return string #Not Yet Implemented
|
||||||
|
*
|
||||||
|
*@see Information\ExcelError::DIV0()
|
||||||
|
* Use the DIV0() method in the Information\Error class instead
|
||||||
|
*/
|
||||||
|
public static function DIV0()
|
||||||
|
{
|
||||||
|
return Information\ExcelError::DIV0();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERROR_TYPE.
|
* ERROR_TYPE.
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
* @return int|string
|
* @return int|string
|
||||||
|
*
|
||||||
|
* @see Information\ExcelError::type()
|
||||||
|
* Use the type() method in the Information\Error class instead
|
||||||
*/
|
*/
|
||||||
public static function errorType($value = '')
|
public static function errorType($value = '')
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
return Information\ExcelError::type($value);
|
||||||
|
|
||||||
$i = 1;
|
|
||||||
foreach (self::$errorCodes as $errorCode) {
|
|
||||||
if ($value === $errorCode) {
|
|
||||||
return $i;
|
|
||||||
}
|
|
||||||
++$i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::NA();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -327,15 +341,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isBlank()
|
||||||
|
* Use the isBlank() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isBlank($value = null)
|
public static function isBlank($value = null)
|
||||||
{
|
{
|
||||||
if ($value !== null) {
|
return Information\Value::isBlank($value);
|
||||||
$value = self::flattenSingleValue($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value === null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -343,13 +358,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isErr()
|
||||||
|
* Use the isErr() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isErr($value = '')
|
public static function isErr($value = '')
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
return Information\Value::isErr($value);
|
||||||
|
|
||||||
return self::isError($value) && (!self::isNa(($value)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -357,17 +375,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isError()
|
||||||
|
* Use the isError() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isError($value = '')
|
public static function isError($value = '')
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
return Information\Value::isError($value);
|
||||||
|
|
||||||
if (!is_string($value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return in_array($value, self::$errorCodes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -375,13 +392,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isNa()
|
||||||
|
* Use the isNa() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isNa($value = '')
|
public static function isNa($value = '')
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
return Information\Value::isNa($value);
|
||||||
|
|
||||||
return $value === self::NA();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -389,19 +409,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isEven()
|
||||||
|
* Use the isEven() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public static function isEven($value = null)
|
public static function isEven($value = null)
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
return Information\Value::isEven($value);
|
||||||
|
|
||||||
if ($value === null) {
|
|
||||||
return self::NAME();
|
|
||||||
} elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
|
|
||||||
return self::VALUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value % 2 == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -409,19 +426,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isOdd()
|
||||||
|
* Use the isOdd() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public static function isOdd($value = null)
|
public static function isOdd($value = null)
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
return Information\Value::isOdd($value);
|
||||||
|
|
||||||
if ($value === null) {
|
|
||||||
return self::NAME();
|
|
||||||
} elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
|
|
||||||
return self::VALUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
return abs($value) % 2 == 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -429,17 +443,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isNumber()
|
||||||
|
* Use the isNumber() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isNumber($value = null)
|
public static function isNumber($value = null)
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
return Information\Value::isNumber($value);
|
||||||
|
|
||||||
if (is_string($value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return is_numeric($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -447,13 +460,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isLogical()
|
||||||
|
* Use the isLogical() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isLogical($value = null)
|
public static function isLogical($value = null)
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
return Information\Value::isLogical($value);
|
||||||
|
|
||||||
return is_bool($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -461,13 +477,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isText()
|
||||||
|
* Use the isText() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isText($value = null)
|
public static function isText($value = null)
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
return Information\Value::isText($value);
|
||||||
|
|
||||||
return is_string($value) && !self::isError($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -475,11 +494,16 @@ class Functions
|
||||||
*
|
*
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isNonText()
|
||||||
|
* Use the isNonText() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isNonText($value = null)
|
public static function isNonText($value = null)
|
||||||
{
|
{
|
||||||
return !self::isText($value);
|
return Information\Value::isNonText($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -487,6 +511,11 @@ class Functions
|
||||||
*
|
*
|
||||||
* Returns a value converted to a number
|
* Returns a value converted to a number
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::asNumber()
|
||||||
|
* Use the asNumber() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @param null|mixed $value The value you want converted
|
* @param null|mixed $value The value you want converted
|
||||||
*
|
*
|
||||||
* @return number N converts values listed in the following table
|
* @return number N converts values listed in the following table
|
||||||
|
|
@ -500,27 +529,7 @@ class Functions
|
||||||
*/
|
*/
|
||||||
public static function n($value = null)
|
public static function n($value = null)
|
||||||
{
|
{
|
||||||
while (is_array($value)) {
|
return Information\Value::asNumber($value);
|
||||||
$value = array_shift($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (gettype($value)) {
|
|
||||||
case 'double':
|
|
||||||
case 'float':
|
|
||||||
case 'integer':
|
|
||||||
return $value;
|
|
||||||
case 'boolean':
|
|
||||||
return (int) $value;
|
|
||||||
case 'string':
|
|
||||||
// Errors
|
|
||||||
if ((strlen($value) > 0) && ($value[0] == '#')) {
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -528,6 +537,11 @@ class Functions
|
||||||
*
|
*
|
||||||
* Returns a number that identifies the type of a value
|
* Returns a number that identifies the type of a value
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::type()
|
||||||
|
* Use the type() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @param null|mixed $value The value you want tested
|
* @param null|mixed $value The value you want tested
|
||||||
*
|
*
|
||||||
* @return number N converts values listed in the following table
|
* @return number N converts values listed in the following table
|
||||||
|
|
@ -540,39 +554,7 @@ class Functions
|
||||||
*/
|
*/
|
||||||
public static function TYPE($value = null)
|
public static function TYPE($value = null)
|
||||||
{
|
{
|
||||||
$value = self::flattenArrayIndexed($value);
|
return Information\Value::type($value);
|
||||||
if (is_array($value) && (count($value) > 1)) {
|
|
||||||
end($value);
|
|
||||||
$a = key($value);
|
|
||||||
// Range of cells is an error
|
|
||||||
if (self::isCellValue($a)) {
|
|
||||||
return 16;
|
|
||||||
// Test for Matrix
|
|
||||||
} elseif (self::isMatrixValue($a)) {
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
} elseif (empty($value)) {
|
|
||||||
// Empty Cell
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
$value = self::flattenSingleValue($value);
|
|
||||||
|
|
||||||
if (($value === null) || (is_float($value)) || (is_int($value))) {
|
|
||||||
return 1;
|
|
||||||
} elseif (is_bool($value)) {
|
|
||||||
return 4;
|
|
||||||
} elseif (is_array($value)) {
|
|
||||||
return 64;
|
|
||||||
} elseif (is_string($value)) {
|
|
||||||
// Errors
|
|
||||||
if ((strlen($value) > 0) && ($value[0] == '#')) {
|
|
||||||
return 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -678,6 +660,11 @@ class Functions
|
||||||
/**
|
/**
|
||||||
* ISFORMULA.
|
* ISFORMULA.
|
||||||
*
|
*
|
||||||
|
* @Deprecated 1.23.0
|
||||||
|
*
|
||||||
|
* @see Information\Value::isFormula()
|
||||||
|
* Use the isFormula() method in the Information\Value class instead
|
||||||
|
*
|
||||||
* @param mixed $cellReference The cell to check
|
* @param mixed $cellReference The cell to check
|
||||||
* @param ?Cell $cell The current cell (containing this formula)
|
* @param ?Cell $cell The current cell (containing this formula)
|
||||||
*
|
*
|
||||||
|
|
@ -685,22 +672,7 @@ class Functions
|
||||||
*/
|
*/
|
||||||
public static function isFormula($cellReference = '', ?Cell $cell = null)
|
public static function isFormula($cellReference = '', ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
if ($cell === null) {
|
return Information\Value::isFormula($cellReference, $cell);
|
||||||
return self::REF();
|
|
||||||
}
|
|
||||||
$cellReference = self::expandDefinedName((string) $cellReference, $cell);
|
|
||||||
$cellReference = self::trimTrailingRange($cellReference);
|
|
||||||
|
|
||||||
preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches);
|
|
||||||
|
|
||||||
$cellReference = $matches[6] . $matches[7];
|
|
||||||
$worksheetName = str_replace("''", "'", trim($matches[2], "'"));
|
|
||||||
|
|
||||||
$worksheet = (!empty($worksheetName))
|
|
||||||
? $cell->getWorksheet()->getParent()->getSheetByName($worksheetName)
|
|
||||||
: $cell->getWorksheet();
|
|
||||||
|
|
||||||
return $worksheet->getCell($cellReference)->isFormula();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function expandDefinedName(string $coordinate, Cell $cell): string
|
public static function expandDefinedName(string $coordinate, Cell $cell): string
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,132 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Information;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
|
class ExcelError
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* List of error codes.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $errorCodes = [
|
||||||
|
'null' => '#NULL!',
|
||||||
|
'divisionbyzero' => '#DIV/0!',
|
||||||
|
'value' => '#VALUE!',
|
||||||
|
'reference' => '#REF!',
|
||||||
|
'name' => '#NAME?',
|
||||||
|
'num' => '#NUM!',
|
||||||
|
'na' => '#N/A',
|
||||||
|
'gettingdata' => '#GETTING_DATA',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERROR_TYPE.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return int|string
|
||||||
|
*/
|
||||||
|
public static function type($value = '')
|
||||||
|
{
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
$i = 1;
|
||||||
|
foreach (self::$errorCodes as $errorCode) {
|
||||||
|
if ($value === $errorCode) {
|
||||||
|
return $i;
|
||||||
|
}
|
||||||
|
++$i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::NA();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NULL.
|
||||||
|
*
|
||||||
|
* Returns the error value #NULL!
|
||||||
|
*
|
||||||
|
* @return string #NULL!
|
||||||
|
*/
|
||||||
|
public static function null()
|
||||||
|
{
|
||||||
|
return self::$errorCodes['null'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NaN.
|
||||||
|
*
|
||||||
|
* Returns the error value #NUM!
|
||||||
|
*
|
||||||
|
* @return string #NUM!
|
||||||
|
*/
|
||||||
|
public static function NAN()
|
||||||
|
{
|
||||||
|
return self::$errorCodes['num'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REF.
|
||||||
|
*
|
||||||
|
* Returns the error value #REF!
|
||||||
|
*
|
||||||
|
* @return string #REF!
|
||||||
|
*/
|
||||||
|
public static function REF()
|
||||||
|
{
|
||||||
|
return self::$errorCodes['reference'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NA.
|
||||||
|
*
|
||||||
|
* Excel Function:
|
||||||
|
* =NA()
|
||||||
|
*
|
||||||
|
* Returns the error value #N/A
|
||||||
|
* #N/A is the error value that means "no value is available."
|
||||||
|
*
|
||||||
|
* @return string #N/A!
|
||||||
|
*/
|
||||||
|
public static function NA()
|
||||||
|
{
|
||||||
|
return self::$errorCodes['na'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VALUE.
|
||||||
|
*
|
||||||
|
* Returns the error value #VALUE!
|
||||||
|
*
|
||||||
|
* @return string #VALUE!
|
||||||
|
*/
|
||||||
|
public static function VALUE()
|
||||||
|
{
|
||||||
|
return self::$errorCodes['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NAME.
|
||||||
|
*
|
||||||
|
* Returns the error value #NAME?
|
||||||
|
*
|
||||||
|
* @return string #NAME?
|
||||||
|
*/
|
||||||
|
public static function NAME()
|
||||||
|
{
|
||||||
|
return self::$errorCodes['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DIV0.
|
||||||
|
*
|
||||||
|
* @return string #Not Yet Implemented
|
||||||
|
*/
|
||||||
|
public static function DIV0()
|
||||||
|
{
|
||||||
|
return self::$errorCodes['divisionbyzero'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,291 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Information;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
|
|
||||||
|
class Value
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* IS_BLANK.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isBlank($value = null)
|
||||||
|
{
|
||||||
|
if ($value !== null) {
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value === null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IS_EVEN.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool|string
|
||||||
|
*/
|
||||||
|
public static function isEven($value = null)
|
||||||
|
{
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
if ($value === null) {
|
||||||
|
return ExcelError::NAME();
|
||||||
|
} elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
|
||||||
|
return ExcelError::VALUE();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value % 2 == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IS_ODD.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool|string
|
||||||
|
*/
|
||||||
|
public static function isOdd($value = null)
|
||||||
|
{
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
if ($value === null) {
|
||||||
|
return ExcelError::NAME();
|
||||||
|
} elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
|
||||||
|
return ExcelError::VALUE();
|
||||||
|
}
|
||||||
|
|
||||||
|
return abs($value) % 2 == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IS_NUMBER.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isNumber($value = null)
|
||||||
|
{
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
if (is_string($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_numeric($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IS_LOGICAL.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isLogical($value = null)
|
||||||
|
{
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
return is_bool($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IS_TEXT.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isText($value = null)
|
||||||
|
{
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
return is_string($value) && !self::isError($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IS_NONTEXT.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isNonText($value = null)
|
||||||
|
{
|
||||||
|
return !self::isText($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ISFORMULA.
|
||||||
|
*
|
||||||
|
* @param mixed $cellReference The cell to check
|
||||||
|
* @param ?Cell $cell The current cell (containing this formula)
|
||||||
|
*
|
||||||
|
* @return bool|string
|
||||||
|
*/
|
||||||
|
public static function isFormula($cellReference = '', ?Cell $cell = null)
|
||||||
|
{
|
||||||
|
if ($cell === null) {
|
||||||
|
return ExcelError::REF();
|
||||||
|
}
|
||||||
|
$cellReference = Functions::expandDefinedName((string) $cellReference, $cell);
|
||||||
|
$cellReference = Functions::trimTrailingRange($cellReference);
|
||||||
|
|
||||||
|
preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches);
|
||||||
|
|
||||||
|
$cellReference = $matches[6] . $matches[7];
|
||||||
|
$worksheetName = str_replace("''", "'", trim($matches[2], "'"));
|
||||||
|
|
||||||
|
$worksheet = (!empty($worksheetName))
|
||||||
|
? $cell->getWorksheet()->getParent()->getSheetByName($worksheetName)
|
||||||
|
: $cell->getWorksheet();
|
||||||
|
|
||||||
|
return ($worksheet !== null) ? $worksheet->getCell($cellReference)->isFormula() : ExcelError::REF();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IS_ERR.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isErr($value = '')
|
||||||
|
{
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
return self::isError($value) && (!self::isNa(($value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IS_ERROR.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isError($value = '')
|
||||||
|
{
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
if (!is_string($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return in_array($value, ExcelError::$errorCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IS_NA.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to check
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isNa($value = '')
|
||||||
|
{
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
return $value === ExcelError::NA();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* N.
|
||||||
|
*
|
||||||
|
* Returns a value converted to a number
|
||||||
|
*
|
||||||
|
* @param null|mixed $value The value you want converted
|
||||||
|
*
|
||||||
|
* @return number N converts values listed in the following table
|
||||||
|
* If value is or refers to N returns
|
||||||
|
* A number That number
|
||||||
|
* A date The serial number of that date
|
||||||
|
* TRUE 1
|
||||||
|
* FALSE 0
|
||||||
|
* An error value The error value
|
||||||
|
* Anything else 0
|
||||||
|
*/
|
||||||
|
public static function asNumber($value = null)
|
||||||
|
{
|
||||||
|
while (is_array($value)) {
|
||||||
|
$value = array_shift($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (gettype($value)) {
|
||||||
|
case 'double':
|
||||||
|
case 'float':
|
||||||
|
case 'integer':
|
||||||
|
return $value;
|
||||||
|
case 'boolean':
|
||||||
|
return (int) $value;
|
||||||
|
case 'string':
|
||||||
|
// Errors
|
||||||
|
if ((strlen($value) > 0) && ($value[0] == '#')) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TYPE.
|
||||||
|
*
|
||||||
|
* Returns a number that identifies the type of a value
|
||||||
|
*
|
||||||
|
* @param null|mixed $value The value you want tested
|
||||||
|
*
|
||||||
|
* @return number N converts values listed in the following table
|
||||||
|
* If value is or refers to N returns
|
||||||
|
* A number 1
|
||||||
|
* Text 2
|
||||||
|
* Logical Value 4
|
||||||
|
* An error value 16
|
||||||
|
* Array or Matrix 64
|
||||||
|
*/
|
||||||
|
public static function type($value = null)
|
||||||
|
{
|
||||||
|
$value = Functions::flattenArrayIndexed($value);
|
||||||
|
if (is_array($value) && (count($value) > 1)) {
|
||||||
|
end($value);
|
||||||
|
$a = key($value);
|
||||||
|
// Range of cells is an error
|
||||||
|
if (Functions::isCellValue($a)) {
|
||||||
|
return 16;
|
||||||
|
// Test for Matrix
|
||||||
|
} elseif (Functions::isMatrixValue($a)) {
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
} elseif (empty($value)) {
|
||||||
|
// Empty Cell
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
$value = Functions::flattenSingleValue($value);
|
||||||
|
|
||||||
|
if (($value === null) || (is_float($value)) || (is_int($value))) {
|
||||||
|
return 1;
|
||||||
|
} elseif (is_bool($value)) {
|
||||||
|
return 4;
|
||||||
|
} elseif (is_array($value)) {
|
||||||
|
return 64;
|
||||||
|
} elseif (is_string($value)) {
|
||||||
|
// Errors
|
||||||
|
if ((strlen($value) > 0) && ($value[0] == '#')) {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Logical;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\Value;
|
||||||
|
|
||||||
class Conditional
|
class Conditional
|
||||||
{
|
{
|
||||||
|
|
@ -45,7 +47,7 @@ class Conditional
|
||||||
*/
|
*/
|
||||||
public static function statementIf($condition = true, $returnIfTrue = 0, $returnIfFalse = false)
|
public static function statementIf($condition = true, $returnIfTrue = 0, $returnIfFalse = false)
|
||||||
{
|
{
|
||||||
if (Functions::isError($condition)) {
|
if (Value::isError($condition)) {
|
||||||
return $condition;
|
return $condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,7 +86,7 @@ class Conditional
|
||||||
*/
|
*/
|
||||||
public static function statementSwitch(...$arguments)
|
public static function statementSwitch(...$arguments)
|
||||||
{
|
{
|
||||||
$result = Functions::VALUE();
|
$result = ExcelError::VALUE();
|
||||||
|
|
||||||
if (count($arguments) > 0) {
|
if (count($arguments) > 0) {
|
||||||
$targetValue = Functions::flattenSingleValue($arguments[0]);
|
$targetValue = Functions::flattenSingleValue($arguments[0]);
|
||||||
|
|
@ -106,7 +108,7 @@ class Conditional
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($switchSatisfied !== true) {
|
if ($switchSatisfied !== true) {
|
||||||
$result = $hasDefaultClause ? $defaultClause : Functions::NA();
|
$result = $hasDefaultClause ? $defaultClause : ExcelError::NA();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +138,7 @@ class Conditional
|
||||||
|
|
||||||
$errorpart = $errorpart ?? '';
|
$errorpart = $errorpart ?? '';
|
||||||
|
|
||||||
return self::statementIf(Functions::isError($testValue), $errorpart, $testValue);
|
return self::statementIf(Value::isError($testValue), $errorpart, $testValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -162,7 +164,7 @@ class Conditional
|
||||||
|
|
||||||
$napart = $napart ?? '';
|
$napart = $napart ?? '';
|
||||||
|
|
||||||
return self::statementIf(Functions::isNa($testValue), $napart, $testValue);
|
return self::statementIf(Value::isNa($testValue), $napart, $testValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -186,7 +188,7 @@ class Conditional
|
||||||
$argumentCount = count($arguments);
|
$argumentCount = count($arguments);
|
||||||
|
|
||||||
if ($argumentCount % 2 != 0) {
|
if ($argumentCount % 2 != 0) {
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
// We use instance of Exception as a falseValue in order to prevent string collision with value in cell
|
// We use instance of Exception as a falseValue in order to prevent string collision with value in cell
|
||||||
$falseValueException = new Exception();
|
$falseValueException = new Exception();
|
||||||
|
|
@ -200,6 +202,6 @@ class Conditional
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Logical;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Operations
|
class Operations
|
||||||
{
|
{
|
||||||
|
|
@ -35,7 +36,7 @@ class Operations
|
||||||
$args = Functions::flattenArray($args);
|
$args = Functions::flattenArray($args);
|
||||||
|
|
||||||
if (count($args) == 0) {
|
if (count($args) == 0) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
$args = array_filter($args, function ($value) {
|
$args = array_filter($args, function ($value) {
|
||||||
|
|
@ -76,7 +77,7 @@ class Operations
|
||||||
$args = Functions::flattenArray($args);
|
$args = Functions::flattenArray($args);
|
||||||
|
|
||||||
if (count($args) == 0) {
|
if (count($args) == 0) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
$args = array_filter($args, function ($value) {
|
$args = array_filter($args, function ($value) {
|
||||||
|
|
@ -118,7 +119,7 @@ class Operations
|
||||||
$args = Functions::flattenArray($args);
|
$args = Functions::flattenArray($args);
|
||||||
|
|
||||||
if (count($args) == 0) {
|
if (count($args) == 0) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
$args = array_filter($args, function ($value) {
|
$args = array_filter($args, function ($value) {
|
||||||
|
|
@ -169,7 +170,7 @@ class Operations
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
return !$logical;
|
return !$logical;
|
||||||
|
|
@ -195,7 +196,7 @@ class Operations
|
||||||
} elseif (($arg == 'FALSE') || ($arg == Calculation::getFALSE())) {
|
} elseif (($arg == 'FALSE') || ($arg == Calculation::getFALSE())) {
|
||||||
$arg = false;
|
$arg = false;
|
||||||
} else {
|
} else {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
$trueValueCount += ($arg != 0);
|
$trueValueCount += ($arg != 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||||
|
|
||||||
class Address
|
class Address
|
||||||
|
|
@ -46,7 +47,7 @@ class Address
|
||||||
$sheetName = Functions::flattenSingleValue($sheetName);
|
$sheetName = Functions::flattenSingleValue($sheetName);
|
||||||
|
|
||||||
if (($row < 1) || ($column < 1)) {
|
if (($row < 1) || ($column < 1)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
$sheetName = self::sheetName($sheetName);
|
$sheetName = self::sheetName($sheetName);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Internal\WildcardMatch;
|
use PhpOffice\PhpSpreadsheet\Calculation\Internal\WildcardMatch;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||||
|
|
||||||
|
|
@ -79,7 +80,7 @@ class ExcelMatch
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unsuccessful in finding a match, return #N/A error value
|
// Unsuccessful in finding a match, return #N/A error value
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function matchFirstValue($lookupArray, $lookupValue)
|
private static function matchFirstValue($lookupArray, $lookupValue)
|
||||||
|
|
@ -149,7 +150,7 @@ class ExcelMatch
|
||||||
{
|
{
|
||||||
// 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($lookupValue)) && (!is_string($lookupValue)) && (!is_bool($lookupValue))) {
|
if ((!is_numeric($lookupValue)) && (!is_string($lookupValue)) && (!is_bool($lookupValue))) {
|
||||||
throw new Exception(Functions::NA());
|
throw new Exception(ExcelError::NA());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,7 +161,7 @@ class ExcelMatch
|
||||||
($matchType !== self::MATCHTYPE_FIRST_VALUE) &&
|
($matchType !== self::MATCHTYPE_FIRST_VALUE) &&
|
||||||
($matchType !== self::MATCHTYPE_LARGEST_VALUE) && ($matchType !== self::MATCHTYPE_SMALLEST_VALUE)
|
($matchType !== self::MATCHTYPE_LARGEST_VALUE) && ($matchType !== self::MATCHTYPE_SMALLEST_VALUE)
|
||||||
) {
|
) {
|
||||||
throw new Exception(Functions::NA());
|
throw new Exception(ExcelError::NA());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,7 +170,7 @@ class ExcelMatch
|
||||||
// Lookup_array should not be empty
|
// Lookup_array should not be empty
|
||||||
$lookupArraySize = count($lookupArray);
|
$lookupArraySize = count($lookupArray);
|
||||||
if ($lookupArraySize <= 0) {
|
if ($lookupArraySize <= 0) {
|
||||||
throw new Exception(Functions::NA());
|
throw new Exception(ExcelError::NA());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,7 +180,7 @@ class ExcelMatch
|
||||||
foreach ($lookupArray as $i => $value) {
|
foreach ($lookupArray as $i => $value) {
|
||||||
// check the type of the value
|
// check the type of the value
|
||||||
if ((!is_numeric($value)) && (!is_string($value)) && (!is_bool($value)) && ($value !== null)) {
|
if ((!is_numeric($value)) && (!is_string($value)) && (!is_bool($value)) && ($value !== null)) {
|
||||||
throw new Exception(Functions::NA());
|
throw new Exception(ExcelError::NA());
|
||||||
}
|
}
|
||||||
// Convert strings to lowercase for case-insensitive testing
|
// Convert strings to lowercase for case-insensitive testing
|
||||||
if (is_string($value)) {
|
if (is_string($value)) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
|
|
||||||
class Formula
|
class Formula
|
||||||
|
|
@ -19,7 +19,7 @@ class Formula
|
||||||
public static function text($cellReference = '', ?Cell $cell = null)
|
public static function text($cellReference = '', ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
if ($cell === null) {
|
if ($cell === null) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches);
|
preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches);
|
||||||
|
|
@ -35,7 +35,7 @@ class Formula
|
||||||
!$worksheet->cellExists($cellReference) ||
|
!$worksheet->cellExists($cellReference) ||
|
||||||
!$worksheet->getCell($cellReference)->isFormula()
|
!$worksheet->getCell($cellReference)->isFormula()
|
||||||
) {
|
) {
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $worksheet->getCell($cellReference)->getValue();
|
return $worksheet->getCell($cellReference)->getValue();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||||
|
|
||||||
|
|
@ -38,7 +39,7 @@ class HLookup extends LookupBase
|
||||||
$f = array_keys($lookupArray);
|
$f = array_keys($lookupArray);
|
||||||
$firstRow = reset($f);
|
$firstRow = reset($f);
|
||||||
if ((!is_array($lookupArray[$firstRow])) || ($indexNumber > count($lookupArray))) {
|
if ((!is_array($lookupArray[$firstRow])) || ($indexNumber > count($lookupArray))) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
$firstkey = $f[0] - 1;
|
$firstkey = $f[0] - 1;
|
||||||
|
|
@ -51,7 +52,7 @@ class HLookup extends LookupBase
|
||||||
return $lookupArray[$returnColumn][Coordinate::stringFromColumnIndex($rowNumber)];
|
return $lookupArray[$returnColumn][Coordinate::stringFromColumnIndex($rowNumber)];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
|
|
||||||
class Hyperlink
|
class Hyperlink
|
||||||
|
|
@ -25,7 +26,7 @@ class Hyperlink
|
||||||
$displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName);
|
$displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName);
|
||||||
|
|
||||||
if ((!is_object($cell)) || (trim($linkURL) == '')) {
|
if ((!is_object($cell)) || (trim($linkURL) == '')) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((is_object($displayName)) || trim($displayName) == '') {
|
if ((is_object($displayName)) || trim($displayName) == '') {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
use Exception;
|
use Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
|
||||||
|
|
@ -23,7 +24,7 @@ class Indirect
|
||||||
return Helpers::CELLADDRESS_USE_A1;
|
return Helpers::CELLADDRESS_USE_A1;
|
||||||
}
|
}
|
||||||
if (is_string($a1fmt)) {
|
if (is_string($a1fmt)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool) $a1fmt;
|
return (bool) $a1fmt;
|
||||||
|
|
@ -38,7 +39,7 @@ class Indirect
|
||||||
{
|
{
|
||||||
$cellAddress = Functions::flattenSingleValue($cellAddress);
|
$cellAddress = Functions::flattenSingleValue($cellAddress);
|
||||||
if (!is_string($cellAddress) || !$cellAddress) {
|
if (!is_string($cellAddress) || !$cellAddress) {
|
||||||
throw new Exception(Functions::REF());
|
throw new Exception(ExcelError::REF());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cellAddress;
|
return $cellAddress;
|
||||||
|
|
@ -77,7 +78,7 @@ class Indirect
|
||||||
(!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress1, $matches)) ||
|
(!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress1, $matches)) ||
|
||||||
(($cellAddress2 !== null) && (!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress2, $matches)))
|
(($cellAddress2 !== null) && (!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress2, $matches)))
|
||||||
) {
|
) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::extractRequiredCells($worksheet, $cellAddress);
|
return self::extractRequiredCells($worksheet, $cellAddress);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
class Lookup
|
class Lookup
|
||||||
|
|
@ -22,7 +23,7 @@ class Lookup
|
||||||
$lookupValue = Functions::flattenSingleValue($lookupValue);
|
$lookupValue = Functions::flattenSingleValue($lookupValue);
|
||||||
|
|
||||||
if (!is_array($lookupVector)) {
|
if (!is_array($lookupVector)) {
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
$hasResultVector = isset($resultVector);
|
$hasResultVector = isset($resultVector);
|
||||||
$lookupRows = self::rowCount($lookupVector);
|
$lookupRows = self::rowCount($lookupVector);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
abstract class LookupBase
|
abstract class LookupBase
|
||||||
{
|
{
|
||||||
|
|
@ -11,12 +11,12 @@ abstract class LookupBase
|
||||||
{
|
{
|
||||||
// index_number must be a number greater than or equal to 1
|
// index_number must be a number greater than or equal to 1
|
||||||
if (!is_numeric($index_number) || $index_number < 1) {
|
if (!is_numeric($index_number) || $index_number < 1) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::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))) {
|
||||||
throw new Exception(Functions::REF());
|
throw new Exception(ExcelError::REF());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $index_number;
|
return (int) $index_number;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\Value;
|
||||||
|
|
||||||
class LookupRefValidations
|
class LookupRefValidations
|
||||||
{
|
{
|
||||||
|
|
@ -13,11 +14,11 @@ class LookupRefValidations
|
||||||
public static function validateInt($value): int
|
public static function validateInt($value): int
|
||||||
{
|
{
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
if (Functions::isError($value)) {
|
if (Value::isError($value)) {
|
||||||
throw new Exception($value);
|
throw new Exception($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) floor((float) $value);
|
return (int) floor((float) $value);
|
||||||
|
|
@ -31,7 +32,7 @@ class LookupRefValidations
|
||||||
$value = self::validateInt($value);
|
$value = self::validateInt($value);
|
||||||
|
|
||||||
if (($allowZero === false && $value <= 0) || $value < 0) {
|
if (($allowZero === false && $value <= 0) || $value < 0) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Matrix
|
class Matrix
|
||||||
{
|
{
|
||||||
|
|
@ -65,14 +66,14 @@ class Matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($matrix) || ($rowNum > count($matrix))) {
|
if (!is_array($matrix) || ($rowNum > count($matrix))) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
$rowKeys = array_keys($matrix);
|
$rowKeys = array_keys($matrix);
|
||||||
$columnKeys = @array_keys($matrix[$rowKeys[0]]);
|
$columnKeys = @array_keys($matrix[$rowKeys[0]]);
|
||||||
|
|
||||||
if ($columnNum > count($columnKeys)) {
|
if ($columnNum > count($columnKeys)) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($columnNum === 0) {
|
if ($columnNum === 0) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
|
@ -48,11 +49,11 @@ class Offset
|
||||||
$width = Functions::flattenSingleValue($width);
|
$width = Functions::flattenSingleValue($width);
|
||||||
|
|
||||||
if ($cellAddress === null || $cellAddress === '') {
|
if ($cellAddress === null || $cellAddress === '') {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_object($cell)) {
|
if (!is_object($cell)) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
[$cellAddress, $worksheet] = self::extractWorksheet($cellAddress, $cell);
|
[$cellAddress, $worksheet] = self::extractWorksheet($cellAddress, $cell);
|
||||||
|
|
@ -69,7 +70,7 @@ class Offset
|
||||||
$startCellColumn += $columns;
|
$startCellColumn += $columns;
|
||||||
|
|
||||||
if (($startCellRow <= 0) || ($startCellColumn < 0)) {
|
if (($startCellRow <= 0) || ($startCellColumn < 0)) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
$endCellColumn = self::adjustEndCellColumnForWidth($endCellColumn, $width, $startCellColumn, $columns);
|
$endCellColumn = self::adjustEndCellColumnForWidth($endCellColumn, $width, $startCellColumn, $columns);
|
||||||
|
|
@ -78,7 +79,7 @@ class Offset
|
||||||
$endCellRow = self::adustEndCellRowForHeight($height, $startCellRow, $rows, $endCellRow);
|
$endCellRow = self::adustEndCellRowForHeight($height, $startCellRow, $rows, $endCellRow);
|
||||||
|
|
||||||
if (($endCellRow <= 0) || ($endCellColumn < 0)) {
|
if (($endCellRow <= 0) || ($endCellColumn < 0)) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
$endCellColumn = Coordinate::stringFromColumnIndex($endCellColumn + 1);
|
$endCellColumn = Coordinate::stringFromColumnIndex($endCellColumn + 1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
|
@ -99,7 +99,7 @@ class RowColumnInformation
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!is_array($cellAddress)) {
|
if (!is_array($cellAddress)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
reset($cellAddress);
|
reset($cellAddress);
|
||||||
|
|
@ -193,7 +193,7 @@ class RowColumnInformation
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!is_array($cellAddress)) {
|
if (!is_array($cellAddress)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
reset($cellAddress);
|
reset($cellAddress);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Selection
|
class Selection
|
||||||
{
|
{
|
||||||
|
|
@ -30,11 +31,11 @@ class Selection
|
||||||
if (is_numeric($chosenEntry)) {
|
if (is_numeric($chosenEntry)) {
|
||||||
--$chosenEntry;
|
--$chosenEntry;
|
||||||
} else {
|
} else {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
$chosenEntry = floor($chosenEntry);
|
$chosenEntry = floor($chosenEntry);
|
||||||
if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) {
|
if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($chooseArgs[$chosenEntry])) {
|
if (is_array($chooseArgs[$chosenEntry])) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||||
|
|
||||||
class VLookup extends LookupBase
|
class VLookup extends LookupBase
|
||||||
|
|
@ -36,7 +37,7 @@ class VLookup extends LookupBase
|
||||||
$f = array_keys($lookupArray);
|
$f = array_keys($lookupArray);
|
||||||
$firstRow = array_pop($f);
|
$firstRow = array_pop($f);
|
||||||
if ((!is_array($lookupArray[$firstRow])) || ($indexNumber > count($lookupArray[$firstRow]))) {
|
if ((!is_array($lookupArray[$firstRow])) || ($indexNumber > count($lookupArray[$firstRow]))) {
|
||||||
return Functions::REF();
|
return ExcelError::REF();
|
||||||
}
|
}
|
||||||
$columnKeys = array_keys($lookupArray[$firstRow]);
|
$columnKeys = array_keys($lookupArray[$firstRow]);
|
||||||
$returnColumn = $columnKeys[--$indexNumber];
|
$returnColumn = $columnKeys[--$indexNumber];
|
||||||
|
|
@ -53,7 +54,7 @@ class VLookup extends LookupBase
|
||||||
return $lookupArray[$rowNumber][$returnColumn];
|
return $lookupArray[$rowNumber][$returnColumn];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function vlookupSort($a, $b)
|
private static function vlookupSort($a, $b)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Arabic
|
class Arabic
|
||||||
{
|
{
|
||||||
|
|
@ -100,7 +100,7 @@ class Arabic
|
||||||
try {
|
try {
|
||||||
$arabic = self::calculateArabic(self::strSplit($roman));
|
$arabic = self::calculateArabic(self::strSplit($roman));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return Functions::VALUE(); // Invalid character detected
|
return ExcelError::VALUE(); // Invalid character detected
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($negativeNumber) {
|
if ($negativeNumber) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Base
|
class Base
|
||||||
{
|
{
|
||||||
|
|
@ -52,7 +52,7 @@ class Base
|
||||||
{
|
{
|
||||||
if ($minLength === null || is_numeric($minLength)) {
|
if ($minLength === null || is_numeric($minLength)) {
|
||||||
if ($number < 0 || $number >= 2 ** 53 || $radix < 2 || $radix > 36) {
|
if ($number < 0 || $number >= 2 ** 53 || $radix < 2 || $radix > 36) {
|
||||||
return Functions::NAN(); // Numeric range constraints
|
return ExcelError::NAN(); // Numeric range constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
$outcome = strtoupper((string) base_convert("$number", 10, $radix));
|
$outcome = strtoupper((string) base_convert("$number", 10, $radix));
|
||||||
|
|
@ -63,6 +63,6 @@ class Base
|
||||||
return $outcome;
|
return $outcome;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Ceiling
|
class Ceiling
|
||||||
{
|
{
|
||||||
|
|
@ -153,7 +154,7 @@ class Ceiling
|
||||||
return ceil($number / $significance) * $significance;
|
return ceil($number / $significance) * $significance;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function floorCheck1Arg(): void
|
private static function floorCheck1Arg(): void
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Floor
|
class Floor
|
||||||
{
|
{
|
||||||
|
|
@ -132,7 +133,7 @@ class Floor
|
||||||
private static function argumentsOkPrecise(float $number, float $significance)
|
private static function argumentsOkPrecise(float $number, float $significance)
|
||||||
{
|
{
|
||||||
if ($significance == 0.0) {
|
if ($significance == 0.0) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
if ($number == 0.0) {
|
if ($number == 0.0) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
@ -149,7 +150,7 @@ class Floor
|
||||||
private static function argsOk(float $number, float $significance, int $mode)
|
private static function argsOk(float $number, float $significance, int $mode)
|
||||||
{
|
{
|
||||||
if (!$significance) {
|
if (!$significance) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
if (!$number) {
|
if (!$number) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
@ -177,7 +178,7 @@ class Floor
|
||||||
private static function argumentsOk(float $number, float $significance)
|
private static function argumentsOk(float $number, float $significance)
|
||||||
{
|
{
|
||||||
if ($significance == 0.0) {
|
if ($significance == 0.0) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
if ($number == 0.0) {
|
if ($number == 0.0) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
@ -189,6 +190,6 @@ class Floor
|
||||||
return floor($number / $significance) * $significance;
|
return floor($number / $significance) * $significance;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Gcd
|
class Gcd
|
||||||
{
|
{
|
||||||
|
|
@ -57,7 +58,7 @@ class Gcd
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($arrayArgs) <= 0) {
|
if (count($arrayArgs) <= 0) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
$gcd = (int) array_pop($arrayArgs);
|
$gcd = (int) array_pop($arrayArgs);
|
||||||
do {
|
do {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Helpers
|
class Helpers
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +15,7 @@ class Helpers
|
||||||
*/
|
*/
|
||||||
public static function verySmallDenominator(float $numerator, float $denominator)
|
public static function verySmallDenominator(float $numerator, float $denominator)
|
||||||
{
|
{
|
||||||
return (abs($denominator) < 1.0E-12) ? Functions::DIV0() : ($numerator / $denominator);
|
return (abs($denominator) < 1.0E-12) ? ExcelError::DIV0() : ($numerator / $denominator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,7 +38,7 @@ class Helpers
|
||||||
return 0 + $number;
|
return 0 + $number;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,7 +59,7 @@ class Helpers
|
||||||
return 0 + $number;
|
return 0 + $number;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -72,7 +73,7 @@ class Helpers
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception($except ?? Functions::NAN());
|
throw new Exception($except ?? ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -86,7 +87,7 @@ class Helpers
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception($except ?? Functions::NAN());
|
throw new Exception($except ?? ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -100,7 +101,7 @@ class Helpers
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(Functions::DIV0());
|
throw new Exception(ExcelError::DIV0());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function returnSign(float $number): int
|
public static function returnSign(float $number): int
|
||||||
|
|
@ -124,6 +125,6 @@ class Helpers
|
||||||
*/
|
*/
|
||||||
public static function numberOrNan($result)
|
public static function numberOrNan($result)
|
||||||
{
|
{
|
||||||
return is_nan($result) ? Functions::NAN() : $result;
|
return is_nan($result) ? ExcelError::NAN() : $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Lcm
|
class Lcm
|
||||||
{
|
{
|
||||||
|
|
@ -104,7 +105,7 @@ class Lcm
|
||||||
private static function testNonNulls(int $anyNonNulls): void
|
private static function testNonNulls(int $anyNonNulls): void
|
||||||
{
|
{
|
||||||
if (!$anyNonNulls) {
|
if (!$anyNonNulls) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use Matrix\Div0Exception as MatrixDiv0Exception;
|
||||||
use Matrix\Exception as MatrixException;
|
use Matrix\Exception as MatrixException;
|
||||||
use Matrix\Matrix;
|
use Matrix\Matrix;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class MatrixFunctions
|
class MatrixFunctions
|
||||||
{
|
{
|
||||||
|
|
@ -31,7 +31,7 @@ class MatrixFunctions
|
||||||
$column = 0;
|
$column = 0;
|
||||||
foreach ($matrixRow as $matrixCell) {
|
foreach ($matrixRow as $matrixCell) {
|
||||||
if ((is_string($matrixCell)) || ($matrixCell === null)) {
|
if ((is_string($matrixCell)) || ($matrixCell === null)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(ExcelError::VALUE());
|
||||||
}
|
}
|
||||||
$matrixData[$row][$column] = $matrixCell;
|
$matrixData[$row][$column] = $matrixCell;
|
||||||
++$column;
|
++$column;
|
||||||
|
|
@ -102,7 +102,7 @@ class MatrixFunctions
|
||||||
|
|
||||||
return $matrix->determinant();
|
return $matrix->determinant();
|
||||||
} catch (MatrixException $ex) {
|
} catch (MatrixException $ex) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
@ -127,9 +127,9 @@ class MatrixFunctions
|
||||||
|
|
||||||
return $matrix->inverse()->toArray();
|
return $matrix->inverse()->toArray();
|
||||||
} catch (MatrixDiv0Exception $e) {
|
} catch (MatrixDiv0Exception $e) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
} catch (MatrixException $e) {
|
} catch (MatrixException $e) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +151,7 @@ class MatrixFunctions
|
||||||
|
|
||||||
return $matrixA->multiply($matrixB)->toArray();
|
return $matrixA->multiply($matrixB)->toArray();
|
||||||
} catch (MatrixException $ex) {
|
} catch (MatrixException $ex) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
@ -168,7 +168,7 @@ class MatrixFunctions
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$dimension = (int) Helpers::validateNumericNullBool($dimension);
|
$dimension = (int) Helpers::validateNumericNullBool($dimension);
|
||||||
Helpers::validatePositive($dimension, Functions::VALUE());
|
Helpers::validatePositive($dimension, ExcelError::VALUE());
|
||||||
$matrix = Builder::createIdentityMatrix($dimension, 0)->toArray();
|
$matrix = Builder::createIdentityMatrix($dimension, 0)->toArray();
|
||||||
|
|
||||||
return $matrix;
|
return $matrix;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Operations
|
class Operations
|
||||||
{
|
{
|
||||||
|
|
@ -75,10 +76,10 @@ class Operations
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if (!$x && !$y) {
|
if (!$x && !$y) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
if (!$x && $y < 0.0) {
|
if (!$x && $y < 0.0) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
|
|
@ -114,7 +115,7 @@ class Operations
|
||||||
$returnValue *= $arg;
|
$returnValue *= $arg;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Random
|
class Random
|
||||||
{
|
{
|
||||||
|
|
@ -78,7 +78,7 @@ class Random
|
||||||
$max = Helpers::validateNumericNullSubstitution($max, 1);
|
$max = Helpers::validateNumericNullSubstitution($max, 1);
|
||||||
|
|
||||||
if ($max <= $min) {
|
if ($max <= $min) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Roman
|
class Roman
|
||||||
{
|
{
|
||||||
|
|
@ -803,12 +803,12 @@ class Roman
|
||||||
|
|
||||||
private static function styleOk(int $aValue, int $style): string
|
private static function styleOk(int $aValue, int $style): string
|
||||||
{
|
{
|
||||||
return ($aValue < 0 || $aValue > self::MAX_ROMAN_VALUE) ? Functions::VALUE() : self::valueOk($aValue, $style);
|
return ($aValue < 0 || $aValue > self::MAX_ROMAN_VALUE) ? ExcelError::VALUE() : self::valueOk($aValue, $style);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function calculateRoman(int $aValue, int $style): string
|
public static function calculateRoman(int $aValue, int $style): string
|
||||||
{
|
{
|
||||||
return ($style < 0 || $style > self::MAX_ROMAN_STYLE) ? Functions::VALUE() : self::styleOk($aValue, $style);
|
return ($style < 0 || $style > self::MAX_ROMAN_STYLE) ? ExcelError::VALUE() : self::styleOk($aValue, $style);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Round
|
class Round
|
||||||
{
|
{
|
||||||
|
|
@ -144,7 +144,7 @@ class Round
|
||||||
return round($number * $multiplier) / $multiplier;
|
return round($number * $multiplier) / $multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||||
|
|
||||||
class Subtotal
|
class Subtotal
|
||||||
|
|
@ -109,6 +110,6 @@ class Subtotal
|
||||||
return call_user_func_array($call, $aArgs);
|
return call_user_func_array($call, $aArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\Value;
|
||||||
|
|
||||||
class Sum
|
class Sum
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +29,7 @@ class Sum
|
||||||
// Is it a numeric value?
|
// Is it a numeric value?
|
||||||
if (is_numeric($arg)) {
|
if (is_numeric($arg)) {
|
||||||
$returnValue += $arg;
|
$returnValue += $arg;
|
||||||
} elseif (Functions::isError($arg)) {
|
} elseif (Value::isError($arg)) {
|
||||||
return $arg;
|
return $arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,11 +63,11 @@ class Sum
|
||||||
$returnValue += $arg;
|
$returnValue += $arg;
|
||||||
} elseif (is_bool($arg)) {
|
} elseif (is_bool($arg)) {
|
||||||
$returnValue += (int) $arg;
|
$returnValue += (int) $arg;
|
||||||
} elseif (Functions::isError($arg)) {
|
} elseif (Value::isError($arg)) {
|
||||||
return $arg;
|
return $arg;
|
||||||
// ignore non-numerics from cell, but fail as literals (except null)
|
// ignore non-numerics from cell, but fail as literals (except null)
|
||||||
} elseif ($arg !== null && !Functions::isCellValue($k)) {
|
} elseif ($arg !== null && !Functions::isCellValue($k)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +101,7 @@ class Sum
|
||||||
$array2 = Functions::flattenArray($matrixData);
|
$array2 = Functions::flattenArray($matrixData);
|
||||||
$count = count($array2);
|
$count = count($array2);
|
||||||
if ($wrkCellCount != $count) {
|
if ($wrkCellCount != $count) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($array2 as $i => $val) {
|
foreach ($array2 as $i => $val) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class SumSquares
|
class SumSquares
|
||||||
{
|
{
|
||||||
|
|
@ -40,7 +41,7 @@ class SumSquares
|
||||||
{
|
{
|
||||||
$count = count($array1);
|
$count = count($array1);
|
||||||
if ($count !== count($array2)) {
|
if ($count !== count($array2)) {
|
||||||
throw new Exception(Functions::NA());
|
throw new Exception(ExcelError::NA());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Trig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers;
|
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers;
|
||||||
|
|
||||||
class Tangent
|
class Tangent
|
||||||
|
|
@ -153,7 +153,7 @@ class Tangent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($xCoordinate == 0) && ($yCoordinate == 0)) {
|
if (($xCoordinate == 0) && ($yCoordinate == 0)) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
return atan2($yCoordinate, $xCoordinate);
|
return atan2($yCoordinate, $xCoordinate);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Averages extends AggregateBase
|
class Averages extends AggregateBase
|
||||||
{
|
{
|
||||||
|
|
@ -27,10 +28,10 @@ class Averages extends AggregateBase
|
||||||
$returnValue = 0.0;
|
$returnValue = 0.0;
|
||||||
|
|
||||||
$aMean = self::average(...$args);
|
$aMean = self::average(...$args);
|
||||||
if ($aMean === Functions::DIV0()) {
|
if ($aMean === ExcelError::DIV0()) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
} elseif ($aMean === Functions::VALUE()) {
|
} elseif ($aMean === ExcelError::VALUE()) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
$aCount = 0;
|
$aCount = 0;
|
||||||
|
|
@ -40,7 +41,7 @@ class Averages extends AggregateBase
|
||||||
// Strings containing numeric values are only counted if they are string literals (not cell values)
|
// Strings containing numeric values are only counted if they are string literals (not cell values)
|
||||||
// and then only in MS Excel and in Open Office, not in Gnumeric
|
// and then only in MS Excel and in Open Office, not in Gnumeric
|
||||||
if ((is_string($arg)) && (!is_numeric($arg)) && (!Functions::isCellValue($k))) {
|
if ((is_string($arg)) && (!is_numeric($arg)) && (!Functions::isCellValue($k))) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
if (self::isAcceptedCountable($arg, $k)) {
|
if (self::isAcceptedCountable($arg, $k)) {
|
||||||
$returnValue += abs($arg - $aMean);
|
$returnValue += abs($arg - $aMean);
|
||||||
|
|
@ -50,7 +51,7 @@ class Averages extends AggregateBase
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
if ($aCount === 0) {
|
if ($aCount === 0) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $returnValue / $aCount;
|
return $returnValue / $aCount;
|
||||||
|
|
@ -79,7 +80,7 @@ class Averages extends AggregateBase
|
||||||
// Strings containing numeric values are only counted if they are string literals (not cell values)
|
// Strings containing numeric values are only counted if they are string literals (not cell values)
|
||||||
// and then only in MS Excel and in Open Office, not in Gnumeric
|
// and then only in MS Excel and in Open Office, not in Gnumeric
|
||||||
if ((is_string($arg)) && (!is_numeric($arg)) && (!Functions::isCellValue($k))) {
|
if ((is_string($arg)) && (!is_numeric($arg)) && (!Functions::isCellValue($k))) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
if (self::isAcceptedCountable($arg, $k)) {
|
if (self::isAcceptedCountable($arg, $k)) {
|
||||||
$returnValue += $arg;
|
$returnValue += $arg;
|
||||||
|
|
@ -92,7 +93,7 @@ class Averages extends AggregateBase
|
||||||
return $returnValue / $aCount;
|
return $returnValue / $aCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -132,7 +133,7 @@ class Averages extends AggregateBase
|
||||||
return $returnValue / $aCount;
|
return $returnValue / $aCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -151,7 +152,7 @@ class Averages extends AggregateBase
|
||||||
{
|
{
|
||||||
$aArgs = Functions::flattenArray($args);
|
$aArgs = Functions::flattenArray($args);
|
||||||
|
|
||||||
$returnValue = Functions::NAN();
|
$returnValue = ExcelError::NAN();
|
||||||
|
|
||||||
$aArgs = self::filterArguments($aArgs);
|
$aArgs = self::filterArguments($aArgs);
|
||||||
$valueCount = count($aArgs);
|
$valueCount = count($aArgs);
|
||||||
|
|
@ -183,7 +184,7 @@ class Averages extends AggregateBase
|
||||||
*/
|
*/
|
||||||
public static function mode(...$args)
|
public static function mode(...$args)
|
||||||
{
|
{
|
||||||
$returnValue = Functions::NA();
|
$returnValue = ExcelError::NA();
|
||||||
|
|
||||||
// Loop through arguments
|
// Loop through arguments
|
||||||
$aArgs = Functions::flattenArray($args);
|
$aArgs = Functions::flattenArray($args);
|
||||||
|
|
@ -251,7 +252,7 @@ class Averages extends AggregateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($maxfreq <= 1) {
|
if ($maxfreq <= 1) {
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $maxfreqdatum;
|
return $maxfreqdatum;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Averages;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Averages;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Averages;
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Averages;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Counts;
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Counts;
|
||||||
|
|
@ -36,7 +37,7 @@ class Mean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -57,7 +58,7 @@ class Mean
|
||||||
// Loop through arguments
|
// Loop through arguments
|
||||||
$aArgs = Functions::flattenArray($args);
|
$aArgs = Functions::flattenArray($args);
|
||||||
if (Minimum::min($aArgs) < 0) {
|
if (Minimum::min($aArgs) < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$returnValue = 0;
|
$returnValue = 0;
|
||||||
|
|
@ -66,7 +67,7 @@ class Mean
|
||||||
// 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 ($arg <= 0) {
|
if ($arg <= 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
$returnValue += (1 / $arg);
|
$returnValue += (1 / $arg);
|
||||||
++$aCount;
|
++$aCount;
|
||||||
|
|
@ -78,7 +79,7 @@ class Mean
|
||||||
return 1 / ($returnValue / $aCount);
|
return 1 / ($returnValue / $aCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -104,7 +105,7 @@ class Mean
|
||||||
|
|
||||||
if ((is_numeric($percent)) && (!is_string($percent))) {
|
if ((is_numeric($percent)) && (!is_string($percent))) {
|
||||||
if (($percent < 0) || ($percent > 1)) {
|
if (($percent < 0) || ($percent > 1)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$mArgs = [];
|
$mArgs = [];
|
||||||
|
|
@ -126,6 +127,6 @@ class Mean
|
||||||
return Averages::average($mArgs);
|
return Averages::average($mArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Confidence
|
class Confidence
|
||||||
{
|
{
|
||||||
|
|
@ -41,7 +42,7 @@ class Confidence
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($alpha <= 0) || ($alpha >= 1) || ($stdDev <= 0) || ($size < 1)) {
|
if (($alpha <= 0) || ($alpha >= 1) || ($stdDev <= 0) || ($size < 1)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::scalar(Distributions\StandardNormal::inverse(1 - $alpha / 2) * $stdDev / sqrt($size));
|
return Functions::scalar(Distributions\StandardNormal::inverse(1 - $alpha / 2) * $stdDev / sqrt($size));
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Deviations
|
class Deviations
|
||||||
{
|
{
|
||||||
|
|
@ -24,7 +25,7 @@ class Deviations
|
||||||
|
|
||||||
$aMean = Averages::average($aArgs);
|
$aMean = Averages::average($aArgs);
|
||||||
if (!is_numeric($aMean)) {
|
if (!is_numeric($aMean)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return value
|
// Return value
|
||||||
|
|
@ -45,7 +46,7 @@ class Deviations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $aCount === 0 ? Functions::VALUE() : $returnValue;
|
return $aCount === 0 ? ExcelError::VALUE() : $returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -65,7 +66,7 @@ class Deviations
|
||||||
$aArgs = Functions::flattenArrayIndexed($args);
|
$aArgs = Functions::flattenArrayIndexed($args);
|
||||||
$mean = Averages::average($aArgs);
|
$mean = Averages::average($aArgs);
|
||||||
if (!is_numeric($mean)) {
|
if (!is_numeric($mean)) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
$stdDev = StandardDeviations::STDEV($aArgs);
|
$stdDev = StandardDeviations::STDEV($aArgs);
|
||||||
|
|
||||||
|
|
@ -90,7 +91,7 @@ class Deviations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,11 +111,11 @@ class Deviations
|
||||||
$aArgs = Functions::flattenArrayIndexed($args);
|
$aArgs = Functions::flattenArrayIndexed($args);
|
||||||
$mean = Averages::average($aArgs);
|
$mean = Averages::average($aArgs);
|
||||||
if (!is_numeric($mean)) {
|
if (!is_numeric($mean)) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
$stdDev = StandardDeviations::STDEV($aArgs);
|
$stdDev = StandardDeviations::STDEV($aArgs);
|
||||||
if ($stdDev === 0.0 || is_string($stdDev)) {
|
if ($stdDev === 0.0 || is_string($stdDev)) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = $summer = 0;
|
$count = $summer = 0;
|
||||||
|
|
@ -122,7 +123,7 @@ class Deviations
|
||||||
foreach ($aArgs as $k => $arg) {
|
foreach ($aArgs as $k => $arg) {
|
||||||
if ((is_bool($arg)) && (!Functions::isMatrixValue($k))) {
|
if ((is_bool($arg)) && (!Functions::isMatrixValue($k))) {
|
||||||
} elseif (!is_numeric($arg)) {
|
} elseif (!is_numeric($arg)) {
|
||||||
return Functions::VALUE();
|
return ExcelError::VALUE();
|
||||||
} else {
|
} else {
|
||||||
// Is it a numeric value?
|
// Is it a numeric value?
|
||||||
if ((is_numeric($arg)) && (!is_string($arg))) {
|
if ((is_numeric($arg)) && (!is_string($arg))) {
|
||||||
|
|
@ -136,6 +137,6 @@ class Deviations
|
||||||
return $summer * ($count / (($count - 1) * ($count - 2)));
|
return $summer * ($count / (($count - 1) * ($count - 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Beta
|
class Beta
|
||||||
{
|
{
|
||||||
|
|
@ -61,7 +62,7 @@ class Beta
|
||||||
$rMax = $tmp;
|
$rMax = $tmp;
|
||||||
}
|
}
|
||||||
if (($value < $rMin) || ($value > $rMax) || ($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax)) {
|
if (($value < $rMin) || ($value > $rMax) || ($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$value -= $rMin;
|
$value -= $rMin;
|
||||||
|
|
@ -115,7 +116,7 @@ class Beta
|
||||||
$rMax = $tmp;
|
$rMax = $tmp;
|
||||||
}
|
}
|
||||||
if (($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax) || ($probability <= 0.0)) {
|
if (($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax) || ($probability <= 0.0)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::calculateInverse($probability, $alpha, $beta, $rMin, $rMax);
|
return self::calculateInverse($probability, $alpha, $beta, $rMin, $rMax);
|
||||||
|
|
@ -143,7 +144,7 @@ class Beta
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($i === self::MAX_ITERATIONS) {
|
if ($i === self::MAX_ITERATIONS) {
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
return round($rMin + $guess * ($rMax - $rMin), 12);
|
return round($rMin + $guess * ($rMax - $rMin), 12);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Combinations;
|
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Combinations;
|
||||||
|
|
||||||
class Binomial
|
class Binomial
|
||||||
|
|
@ -49,7 +50,7 @@ class Binomial
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($value < 0) || ($value > $trials)) {
|
if (($value < 0) || ($value > $trials)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cumulative) {
|
if ($cumulative) {
|
||||||
|
|
@ -98,10 +99,10 @@ class Binomial
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($successes < 0) || ($successes > $trials)) {
|
if (($successes < 0) || ($successes > $trials)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
if (($limit < 0) || ($limit > $trials) || $limit < $successes) {
|
if (($limit < 0) || ($limit > $trials) || $limit < $successes) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$summer = 0;
|
$summer = 0;
|
||||||
|
|
@ -151,11 +152,11 @@ class Binomial
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($failures < 0) || ($successes < 1)) {
|
if (($failures < 0) || ($successes < 1)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
|
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
|
||||||
if (($failures + $successes - 1) <= 0) {
|
if (($failures + $successes - 1) <= 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,9 +196,9 @@ class Binomial
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($trials < 0) {
|
if ($trials < 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
} elseif (($alpha < 0.0) || ($alpha > 1.0)) {
|
} elseif (($alpha < 0.0) || ($alpha > 1.0)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$successes = 0;
|
$successes = 0;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class ChiSquared
|
class ChiSquared
|
||||||
{
|
{
|
||||||
|
|
@ -42,14 +43,14 @@ class ChiSquared
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($degrees < 1) {
|
if ($degrees < 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
if ($value < 0) {
|
if ($value < 0) {
|
||||||
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
|
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1 - (Gamma::incompleteGamma($degrees / 2, $value / 2) / Gamma::gammaValue($degrees / 2));
|
return 1 - (Gamma::incompleteGamma($degrees / 2, $value / 2) / Gamma::gammaValue($degrees / 2));
|
||||||
|
|
@ -86,14 +87,14 @@ class ChiSquared
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($degrees < 1) {
|
if ($degrees < 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
if ($value < 0) {
|
if ($value < 0) {
|
||||||
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
|
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cumulative === true) {
|
if ($cumulative === true) {
|
||||||
|
|
@ -132,7 +133,7 @@ class ChiSquared
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($degrees < 1) {
|
if ($degrees < 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$callback = function ($value) use ($degrees) {
|
$callback = function ($value) use ($degrees) {
|
||||||
|
|
@ -173,7 +174,7 @@ class ChiSquared
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($degrees < 1) {
|
if ($degrees < 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::inverseLeftTailCalculation($probability, $degrees);
|
return self::inverseLeftTailCalculation($probability, $degrees);
|
||||||
|
|
@ -201,15 +202,15 @@ class ChiSquared
|
||||||
$countActuals = count($actual);
|
$countActuals = count($actual);
|
||||||
$countExpected = count($expected);
|
$countExpected = count($expected);
|
||||||
if ($countActuals !== $countExpected || $countActuals === 1) {
|
if ($countActuals !== $countExpected || $countActuals === 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = 0.0;
|
$result = 0.0;
|
||||||
for ($i = 0; $i < $countActuals; ++$i) {
|
for ($i = 0; $i < $countActuals; ++$i) {
|
||||||
if ($expected[$i] == 0.0) {
|
if ($expected[$i] == 0.0) {
|
||||||
return Functions::DIV0();
|
return ExcelError::DIV0();
|
||||||
} elseif ($expected[$i] < 0.0) {
|
} elseif ($expected[$i] < 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
$result += (($actual[$i] - $expected[$i]) ** 2) / $expected[$i];
|
$result += (($actual[$i] - $expected[$i]) ** 2) / $expected[$i];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\StatisticalValidations;
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\StatisticalValidations;
|
||||||
|
|
||||||
class DistributionValidations extends StatisticalValidations
|
class DistributionValidations extends StatisticalValidations
|
||||||
|
|
@ -16,7 +16,7 @@ class DistributionValidations extends StatisticalValidations
|
||||||
$probability = self::validateFloat($probability);
|
$probability = self::validateFloat($probability);
|
||||||
|
|
||||||
if ($probability < 0.0 || $probability > 1.0) {
|
if ($probability < 0.0 || $probability > 1.0) {
|
||||||
throw new Exception(Functions::NAN());
|
throw new Exception(ExcelError::NAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $probability;
|
return $probability;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Exponential
|
class Exponential
|
||||||
{
|
{
|
||||||
|
|
@ -43,7 +43,7 @@ class Exponential
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($value < 0) || ($lambda < 0)) {
|
if (($value < 0) || ($lambda < 0)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cumulative === true) {
|
if ($cumulative === true) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class F
|
class F
|
||||||
{
|
{
|
||||||
|
|
@ -47,7 +47,7 @@ class F
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value < 0 || $u < 1 || $v < 1) {
|
if ($value < 0 || $u < 1 || $v < 1) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cumulative) {
|
if ($cumulative) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Fisher
|
class Fisher
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +37,7 @@ class Fisher
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($value <= -1) || ($value >= 1)) {
|
if (($value <= -1) || ($value >= 1)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0.5 * log((1 + $value) / (1 - $value));
|
return 0.5 * log((1 + $value) / (1 - $value));
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class Gamma extends GammaBase
|
class Gamma extends GammaBase
|
||||||
{
|
{
|
||||||
|
|
@ -35,7 +35,7 @@ class Gamma extends GammaBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((((int) $value) == ((float) $value)) && $value <= 0.0) {
|
if ((((int) $value) == ((float) $value)) && $value <= 0.0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::gammaValue($value);
|
return self::gammaValue($value);
|
||||||
|
|
@ -75,7 +75,7 @@ class Gamma extends GammaBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($value < 0) || ($a <= 0) || ($b <= 0)) {
|
if (($value < 0) || ($a <= 0) || ($b <= 0)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::calculateDistribution($value, $a, $b, $cumulative);
|
return self::calculateDistribution($value, $a, $b, $cumulative);
|
||||||
|
|
@ -112,7 +112,7 @@ class Gamma extends GammaBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($alpha <= 0.0) || ($beta <= 0.0)) {
|
if (($alpha <= 0.0) || ($beta <= 0.0)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::calculateInverse($probability, $alpha, $beta);
|
return self::calculateInverse($probability, $alpha, $beta);
|
||||||
|
|
@ -143,7 +143,7 @@ class Gamma extends GammaBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value <= 0) {
|
if ($value <= 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return log(self::gammaValue($value));
|
return log(self::gammaValue($value));
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
abstract class GammaBase
|
abstract class GammaBase
|
||||||
{
|
{
|
||||||
|
|
@ -65,7 +66,7 @@ abstract class GammaBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($i === self::MAX_ITERATIONS) {
|
if ($i === self::MAX_ITERATIONS) {
|
||||||
return Functions::NA();
|
return ExcelError::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $x;
|
return $x;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Combinations;
|
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Combinations;
|
||||||
|
|
||||||
class HyperGeometric
|
class HyperGeometric
|
||||||
|
|
@ -55,13 +55,13 @@ class HyperGeometric
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($sampleSuccesses < 0) || ($sampleSuccesses > $sampleNumber) || ($sampleSuccesses > $populationSuccesses)) {
|
if (($sampleSuccesses < 0) || ($sampleSuccesses > $sampleNumber) || ($sampleSuccesses > $populationSuccesses)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
if (($sampleNumber <= 0) || ($sampleNumber > $populationNumber)) {
|
if (($sampleNumber <= 0) || ($sampleNumber > $populationNumber)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
if (($populationSuccesses <= 0) || ($populationSuccesses > $populationNumber)) {
|
if (($populationSuccesses <= 0) || ($populationSuccesses > $populationNumber)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$successesPopulationAndSample = (float) Combinations::withoutRepetition($populationSuccesses, $sampleSuccesses);
|
$successesPopulationAndSample = (float) Combinations::withoutRepetition($populationSuccesses, $sampleSuccesses);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||||
|
|
||||||
class LogNormal
|
class LogNormal
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +42,7 @@ class LogNormal
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($value <= 0) || ($stdDev <= 0)) {
|
if (($value <= 0) || ($stdDev <= 0)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return StandardNormal::cumulative((log($value) - $mean) / $stdDev);
|
return StandardNormal::cumulative((log($value) - $mean) / $stdDev);
|
||||||
|
|
@ -83,7 +83,7 @@ class LogNormal
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($value <= 0) || ($stdDev <= 0)) {
|
if (($value <= 0) || ($stdDev <= 0)) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cumulative === true) {
|
if ($cumulative === true) {
|
||||||
|
|
@ -129,7 +129,7 @@ class LogNormal
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($stdDev <= 0) {
|
if ($stdDev <= 0) {
|
||||||
return Functions::NAN();
|
return ExcelError::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
return exp($mean + $stdDev * StandardNormal::inverse($probability));
|
return exp($mean + $stdDev * StandardNormal::inverse($probability));
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue