Custom functions not running when workbook opened with custom function in it

Posted by: dean.kinnear on 3 January 2023, 5:03 am EST

    • Post Options:
    • Link

    Posted 3 January 2023, 5:03 am EST

    custom functions seem to only run when manually entering a custom formula.

    If I open a workbook that already has that custom function in a formula, it is not running automatically and returns a #NAME? error.

    If I copy the same formula to another cell, that instance of the custom function runs.

  • Posted 3 January 2023, 5:07 pm EST

    Hi Dean,

    As per my understanding, you have a custom function that you have defined and added it to the workbook/worksheet. You export the json and then import the json having the custom function, and you are getting the “#NAME” error on the cell(s) having custom function.

    If this is the use case, you need to add Custom Item Serialization that allows saving and loading workbooks between instances and preserving custom items.

    You can refer to the following demo: https://www.grapecity.com/spreadjs/demos/features/workbook/custom-item-serialization/purejs

    Sample: https://jscodemine.grapecity.com/share/HR28adQSHUCyGo32jckQdA/?defaultOpen={"OpenedFileName"%3A["%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}

    Please let us know if you have a different use case. You could also modify the sample and share with us replicating the issue.

    Regards,

    Ankit

  • Posted 4 January 2023, 12:30 am EST - Updated 4 January 2023, 12:34 am EST

    I have a workbook with a custom function “myfunc”.

    An addin that runs in Excel sets the custom function’s value to “Hello from addin”

    When I try to load that workbook in spreadjs, the custom function does not run on open and displays #Name? error.

    I add the custom function like this:

    //spread.addCustomFunction(new myfunc()); This didnt work

    spread.fromJSON(json);

    spread.addCustomFunction(new myfunc()); //I cant add this before I load workbook from json or the custom function won’t work at all

    Javascript function :

    myfunc.prototype = new GC.Spread.CalcEngine.Functions.Function();

    function myfunc() {

    this.name = ‘myfunc’;

    this.maxArgs = 0;

    this.minArgs = 0;

    }

    myfunc.prototype.evaluate = function () {

    return “Hello from speadjs”;

    }

    I can add the function manually in the UI, but I can’t get it to run on open.

    Here is a demo of what I am referring to:

    chrome_8hBWoX6Non.zip

  • Posted 4 January 2023, 5:50 pm EST

    Hi,

    Could you please share a working sample and steps by which we could replicate the issue at our end so that we could investigate it further and help you accordingly?

    Regards,

    Avinash

  • Posted 16 May 2023, 11:50 am EST

    Hi,

    I am evaluating Spreadjs and I encounter the same problem.

    I have a VBA custom function in Excel (I_COEFMOY(). I load Spreadjs with the Excel file and recreate the same custom function name in Spreadjs.

    At the time of loading with spread.fromJSON(json);, I think the function is not recognized and the file reflects the problem.

    Even if I add the custom function afterwards with spread.addCustomFunction(oCoefMoy); , the initial state in the way remains as long as I do not make any change in the cell (for example:

    sheet.setFormula(7, 5, “FOO()”);

    sheet.setFormula(7, 6, “FOO()”);

    sheet.setFormula(7, 5, “I_COEFMOY($E9:$E11,F9:F11)”);

    sheet.setFormula(7, 6, “I_COEFMOY($E9:$E11,G9:G11)”);

    )

    Isn’t there a way to force the recalculation of the entire sheet?

    Thank you for your response,

    Gerald

  • Posted 16 May 2023, 9:07 pm EST

    Hi,

    I found the solution.

    The custom function must be defined before using spread.fromJSON(json); and the function must be declared as global with :

    spread.addCustomFunction(MyFunct);

    GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction(“MYFUNCT”, MyFunct);

  • Posted 16 May 2023, 10:32 pm EST

    Hello,

    We are happy to hear that the issue you were facing has been resolved. Please let us know if you face any difficulties in future. We will make sure to help you accordingly.

    You may refer to https://www.grapecity.com/spreadjs/demos/features/workbook/custom-item-serialization#demo_source_name and https://www.grapecity.com/spreadjs/docs/features/serialization#site_main_content-doc-content_title links for more information regarding serialization of the custom functions.

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels