Skip to content

Add support for custom Calculation functions #2900

Closed
@looksystems

Description

@looksystems

This is:

- [x] a feature request

What is the expected behavior?

Add ability to add own calculation functions / implementations.

What is the current behavior?

Currently, Calculation class (and it's usage within Spreadsheet) is private and cannot be overridden or extended without changes to the source code.

In particular, Calculation::$phpSpreadsheetFunctions is private and there are no methods available to add/override function.

Proposal: add the following method to the Calculation class...

    public static function registerFunction(string $name, array $definition)
    {
        self::$phpSpreadsheetFunctions[$name] = $definition;
    }

ALSO

Calculation::addDefaultArgumentValues only supports static methods (for Calculation functions):

** Proposal:** modify addDefaultArgumentValues...

    private function addDefaultArgumentValues(array $functionCall, array $args, array $emptyArguments): array
    {
        if (is_object($functionCall[0])) {
            $reflector = new ReflectionMethod($functionCall[0], $functionCall[1]);
        } else {
            $reflector = new ReflectionMethod(implode('::', $functionCall));
        }

        $methodArguments = $reflector->getParameters();

What are the steps to reproduce?

N/A

What features do you think are causing the issue

  • Formula Calulations

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Yes

Which versions of PhpSpreadsheet and PHP are affected?

Latest PhpSpreadsheet and all supported versions of php.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions