mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-24 17:19:29 +00:00
53bce34456
For an overview of why this is desired (and ways that people have coped with its absence), see issue #2900 and issue #4048; also PR #4043 which will be superseded by this PR. The list of Excel functions is moved from Calculation/Calculation to its own member. I believe that it is done in a way that will not cause big complications to two experiments from @MarkBaker (PR #2714 and PR #2734). I believe it is also done in such a way that further refactoring of Calculation can follow this model. Custom functions can be added or removed from the function list. You cannot add a function if it already exists in the list, and you cannot remove a non-custom function from the list. They will, of course, not be understood by Excel if written to a spreadsheet; the use case is mainly using the Calculation engine outside of spreadsheet context.
23 lines
518 B
PHP
23 lines
518 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers;
|
|
|
|
class CustomFunction
|
|
{
|
|
public static function fourthPower(mixed $number): float|int|string
|
|
{
|
|
try {
|
|
$number = Helpers::validateNumericNullBool($number);
|
|
} catch (CalcException $e) {
|
|
return $e->getMessage();
|
|
}
|
|
|
|
return $number ** 4;
|
|
}
|
|
}
|