Fix Exception cases to always use the PhpSpreadsheet Calculation Exception
This commit is contained in:
parent
71bc7e6f89
commit
fb251eb6ab
|
|
@ -2329,7 +2329,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'SUMPRODUCT' => [
|
'SUMPRODUCT' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig\SumProduct::class, 'evaluate'],
|
'functionCall' => [MathTrig\Sum::class, 'product'],
|
||||||
'argumentCount' => '1+',
|
'argumentCount' => '1+',
|
||||||
],
|
],
|
||||||
'SUMSQ' => [
|
'SUMSQ' => [
|
||||||
|
|
|
||||||
|
|
@ -840,8 +840,8 @@ class MathTrig
|
||||||
*
|
*
|
||||||
* @Deprecated 1.18.0
|
* @Deprecated 1.18.0
|
||||||
*
|
*
|
||||||
* @See MathTrig\SumProduct::evaluate()
|
* @See MathTrig\Sum::product()
|
||||||
* Use the evaluate method in the MathTrig\SumProduct class instead
|
* Use the product method in the MathTrig\Sum class instead
|
||||||
*
|
*
|
||||||
* @param mixed ...$args Data values
|
* @param mixed ...$args Data values
|
||||||
*
|
*
|
||||||
|
|
@ -849,7 +849,7 @@ class MathTrig
|
||||||
*/
|
*/
|
||||||
public static function SUMPRODUCT(...$args)
|
public static function SUMPRODUCT(...$args)
|
||||||
{
|
{
|
||||||
return MathTrig\SumProduct::evaluate(...$args);
|
return MathTrig\Sum::product(...$args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class Arabic
|
class Arabic
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class Base
|
class Base
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
|
|
||||||
class Degrees
|
class Degrees
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
|
|
||||||
class Exp
|
class Exp
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
|
|
||||||
class IntClass
|
class IntClass
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
|
|
||||||
class Mod
|
class Mod
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class Power
|
class Power
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
|
|
||||||
class Quotient
|
class Quotient
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
|
|
||||||
class Radians
|
class Radians
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class Roman
|
class Roman
|
||||||
|
|
@ -769,6 +769,7 @@ class Roman
|
||||||
3998 => ['MMMLMVLIII', 'MMMXMVIII', 'MMMVMIII'],
|
3998 => ['MMMLMVLIII', 'MMMXMVIII', 'MMMVMIII'],
|
||||||
3999 => ['MMMLMVLIV', 'MMMXMIX', 'MMMVMIV', 'MMMIM'],
|
3999 => ['MMMLMVLIV', 'MMMXMIX', 'MMMVMIV', 'MMMIM'],
|
||||||
];
|
];
|
||||||
|
|
||||||
private const THOUSANDS = ['', 'M', 'MM', 'MMM'];
|
private const THOUSANDS = ['', 'M', 'MM', 'MMM'];
|
||||||
private const HUNDREDS = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'];
|
private const HUNDREDS = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'];
|
||||||
private const TENS = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'];
|
private const TENS = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'];
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class SeriesSum
|
class SeriesSum
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
|
|
||||||
class Sign
|
class Sign
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ class Subtotal
|
||||||
|
|
||||||
/** @var callable[] */
|
/** @var callable[] */
|
||||||
private const CALL_FUNCTIONS = [
|
private const CALL_FUNCTIONS = [
|
||||||
1 => [Statistical\Averages::class, 'AVERAGE'],
|
1 => [Statistical\Averages::class, 'average'],
|
||||||
[Statistical\Counts::class, 'COUNT'], // 2
|
[Statistical\Counts::class, 'COUNT'], // 2
|
||||||
[Statistical\Counts::class, 'COUNTA'], // 3
|
[Statistical\Counts::class, 'COUNTA'], // 3
|
||||||
[Statistical\Maximum::class, 'MAX'], // 4
|
[Statistical\Maximum::class, 'MAX'], // 4
|
||||||
|
|
|
||||||
|
|
@ -71,4 +71,45 @@ class Sum
|
||||||
|
|
||||||
return $returnValue;
|
return $returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SUMPRODUCT.
|
||||||
|
*
|
||||||
|
* Excel Function:
|
||||||
|
* SUMPRODUCT(value1[,value2[, ...]])
|
||||||
|
*
|
||||||
|
* @param mixed ...$args Data values
|
||||||
|
*
|
||||||
|
* @return float|string The result, or a string containing an error
|
||||||
|
*/
|
||||||
|
public static function product(...$args)
|
||||||
|
{
|
||||||
|
$arrayList = $args;
|
||||||
|
|
||||||
|
$wrkArray = Functions::flattenArray(array_shift($arrayList));
|
||||||
|
$wrkCellCount = count($wrkArray);
|
||||||
|
|
||||||
|
for ($i = 0; $i < $wrkCellCount; ++$i) {
|
||||||
|
if ((!is_numeric($wrkArray[$i])) || (is_string($wrkArray[$i]))) {
|
||||||
|
$wrkArray[$i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($arrayList as $matrixData) {
|
||||||
|
$array2 = Functions::flattenArray($matrixData);
|
||||||
|
$count = count($array2);
|
||||||
|
if ($wrkCellCount != $count) {
|
||||||
|
return Functions::VALUE();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($array2 as $i => $val) {
|
||||||
|
if ((!is_numeric($val)) || (is_string($val))) {
|
||||||
|
$val = 0;
|
||||||
|
}
|
||||||
|
$wrkArray[$i] *= $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_sum($wrkArray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
|
|
||||||
class SumProduct
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* SUMPRODUCT.
|
|
||||||
*
|
|
||||||
* Excel Function:
|
|
||||||
* SUMPRODUCT(value1[,value2[, ...]])
|
|
||||||
*
|
|
||||||
* @param mixed ...$args Data values
|
|
||||||
*
|
|
||||||
* @return float|string The result, or a string containing an error
|
|
||||||
*/
|
|
||||||
public static function evaluate(...$args)
|
|
||||||
{
|
|
||||||
$arrayList = $args;
|
|
||||||
|
|
||||||
$wrkArray = Functions::flattenArray(array_shift($arrayList));
|
|
||||||
$wrkCellCount = count($wrkArray);
|
|
||||||
|
|
||||||
for ($i = 0; $i < $wrkCellCount; ++$i) {
|
|
||||||
if ((!is_numeric($wrkArray[$i])) || (is_string($wrkArray[$i]))) {
|
|
||||||
$wrkArray[$i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($arrayList as $matrixData) {
|
|
||||||
$array2 = Functions::flattenArray($matrixData);
|
|
||||||
$count = count($array2);
|
|
||||||
if ($wrkCellCount != $count) {
|
|
||||||
return Functions::VALUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($array2 as $i => $val) {
|
|
||||||
if ((!is_numeric($val)) || (is_string($val))) {
|
|
||||||
$val = 0;
|
|
||||||
}
|
|
||||||
$wrkArray[$i] *= $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_sum($wrkArray);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class SumSquares
|
class SumSquares
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
|
|
||||||
class Trunc
|
class Trunc
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue