Extend PhpSpreadsheet with a custom function #2118
-
Hi, My purpose is to calculate MAX, MIN, AVG, COUNT, ... from a string like "123+456+78+90". Thanks for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Surely this should just be something that you implement in your own code, calling the appropriate functions from PHPSpreadsheet |
Beta Was this translation helpful? Give feedback.
-
No, you can't calculate MAX, MIN, AVG, COUNT and SUM from a single string in MS Excel; what you'd have to do is split that string into an array of values, which is much easier done in PHP than in Excel; then pass that array as an argument to the relevant Excel function implementations to get the results. $inputString = "123+456+78+90";
$dataValues = explode('+', $inputString);
$max = \PhpOffice\PhpSpreadsheet\Calculation\Statistical\Maximum::max(...$dataValues);
$min = \PhpOffice\PhpSpreadsheet\Calculation\Statistical\Minimum::min(...$dataValues);
...etc |
Beta Was this translation helpful? Give feedback.
No, you can't calculate MAX, MIN, AVG, COUNT and SUM from a single string in MS Excel; what you'd have to do is split that string into an array of values, which is much easier done in PHP than in Excel; then pass that array as an argument to the relevant Excel function implementations to get the results.