diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index dabe6308..4249ea3f 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -2329,7 +2329,7 @@ class Calculation ], 'SUMPRODUCT' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig\SumProduct::class, 'evaluate'], + 'functionCall' => [MathTrig\Sum::class, 'product'], 'argumentCount' => '1+', ], 'SUMSQ' => [ diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php index 14614004..ea4c265d 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig.php @@ -840,8 +840,8 @@ class MathTrig * * @Deprecated 1.18.0 * - * @See MathTrig\SumProduct::evaluate() - * Use the evaluate method in the MathTrig\SumProduct class instead + * @See MathTrig\Sum::product() + * Use the product method in the MathTrig\Sum class instead * * @param mixed ...$args Data values * @@ -849,7 +849,7 @@ class MathTrig */ public static function SUMPRODUCT(...$args) { - return MathTrig\SumProduct::evaluate(...$args); + return MathTrig\Sum::product(...$args); } /** diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php b/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php index b3d8c330..b852eeac 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Arabic diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Base.php b/src/PhpSpreadsheet/Calculation/MathTrig/Base.php index 373bcf08..becba9a2 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Base.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Base.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Base diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Degrees.php b/src/PhpSpreadsheet/Calculation/MathTrig/Degrees.php index 501817be..317c47c8 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Degrees.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Degrees.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; class Degrees { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Exp.php b/src/PhpSpreadsheet/Calculation/MathTrig/Exp.php index f3f8af59..ce930a83 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Exp.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Exp.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; class Exp { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php b/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php index c8f35e48..7aa3d06a 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; class IntClass { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Mod.php b/src/PhpSpreadsheet/Calculation/MathTrig/Mod.php index 04267ee9..813434ad 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Mod.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Mod.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; class Mod { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Power.php b/src/PhpSpreadsheet/Calculation/MathTrig/Power.php index 70d177cd..798ad535 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Power.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Power.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Power diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Quotient.php b/src/PhpSpreadsheet/Calculation/MathTrig/Quotient.php index 774b5fa1..9beb493a 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Quotient.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Quotient.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; class Quotient { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Radians.php b/src/PhpSpreadsheet/Calculation/MathTrig/Radians.php index 15e97011..ca549c03 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Radians.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Radians.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; class Radians { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php b/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php index 865a5101..71a6df3a 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Roman @@ -769,6 +769,7 @@ class Roman 3998 => ['MMMLMVLIII', 'MMMXMVIII', 'MMMVMIII'], 3999 => ['MMMLMVLIV', 'MMMXMIX', 'MMMVMIV', 'MMMIM'], ]; + private const THOUSANDS = ['', 'M', 'MM', 'MMM']; private const HUNDREDS = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM']; private const TENS = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC']; diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php b/src/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php index 73238214..2ada9df4 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class SeriesSum diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php index 1b955a80..a48cf0f9 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; class Sign { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php b/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php index c60842f7..946142a7 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Statistical; @@ -52,7 +52,7 @@ class Subtotal /** @var callable[] */ private const CALL_FUNCTIONS = [ - 1 => [Statistical\Averages::class, 'AVERAGE'], + 1 => [Statistical\Averages::class, 'average'], [Statistical\Counts::class, 'COUNT'], // 2 [Statistical\Counts::class, 'COUNTA'], // 3 [Statistical\Maximum::class, 'MAX'], // 4 diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php index cffa68c5..741734d9 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php @@ -71,4 +71,45 @@ class Sum 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); + } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/SumProduct.php b/src/PhpSpreadsheet/Calculation/MathTrig/SumProduct.php deleted file mode 100644 index 7700d008..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/SumProduct.php +++ /dev/null @@ -1,49 +0,0 @@ - $val) { - if ((!is_numeric($val)) || (is_string($val))) { - $val = 0; - } - $wrkArray[$i] *= $val; - } - } - - return array_sum($wrkArray); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php b/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php index a750b149..49fa6381 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class SumSquares diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php index 0a1c827e..4b3670f6 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; class Trunc {