FunctionExpression object for CustomFunction

Posted by: aspnetdev on 8 September 2017, 2:58 pm EST

  • Posted 8 September 2017, 2:58 pm EST

    I am trying to access instance of the CustomFunction associated with a cell. For that I found I can use FunctionExpression.

    But for CustomFunction FunctionExpression's Function property is Null - whereas if its not a custom function, I can access Function property.

    I read in another forum post that Farpoint uses late binding for Custom Function. My question is, is there any way I can have this Function property set to correct instance for the custom function as well ? 

                        FarPoint.CalcEngine.Expression ex = fpSpread1.ActiveSheet.GetExpression(rowIndex, columnIndex);
                        if (ex != null && ex is FarPoint.CalcEngine.FunctionExpression)
                            FarPoint.CalcEngine.FunctionExpression fex = ex as FarPoint.CalcEngine.FunctionExpression;

                          <span> // fex.Function  is null here for CustomFunctions.</span>


  • Replied 8 September 2017, 2:58 pm EST


    When application sets Formula property or user types formula into cell, Spread parses the text representation of the formula into an Expression object. Spread uses early binding for built-in functions (i.e. lookup function name to find FunctionInfo object and store FunctionInfo object in FunctionExpression object at parse time). Spread uses late binding for custom functins (i.e. store function name in FunctionInfo object at parse time and then later lookup function name to find FunctionInfo object at evaluation time). This is the same way that Excel works. Late binding gives you the flexibility to create the formula before creating the custom function. Late binding also gives you the flexibility to change the custom function.

    In your code, you will need to check for late bound functions and look them up in the custom function table. For example...


    FunctionInfo func = fex.Function;
    if (func == null)
        func = fpSpread1.ActiveSheet.GetCustomFunction(fex.FunctionName);
    if (func == null)
        ...; // handle undefined functions
        ...; // handle built-in and custom functions

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels