Skip to content

Extend PhpSpreadsheet with a custom function #2118

Answered by MarkBaker
robertotremonti asked this question in Q&A
Discussion options

You must be logged in to vote

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

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@robertotremonti
Comment options

@robertotremonti
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by oleibman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants