Is it possible to create custom functions that can be used as formulas? For instance "=MyFunction(A1:A10)"?
I am happy to hear that!
Best regards,Alexander
Hello Alex,
This looks like it will meet my needs. Thank you for the working example! :)
Hello Brian,
I am writing to add some information on your scenario that was provided by the development team.
As a temporary workaround, while the feature is implemented, you can use this example: http://jsfiddle.net/fcj2dupv/
The example demonstrates hot to write a helper function in that page that creates a new derived calc function. Then the usage is 2 parts. One is to define the function.
e.g.
createCustomFunction("SumTwo", 2, 2, function(numberStack, argumentCount) { var second = numberStack.pop(); var first = numberStack.pop(); return new $.ig.excel.ExcelCalcValue(first.toDouble() + second.toDouble()); });
The other is to register an instance of it with the workbook:
function setWorkbook() { if ($("#spreadsheet").igSpreadsheet !== undefined && workbook != null) { workbook.registerUserDefinedFunction(new $.ig.CustomFunctions.SumEx()); workbook.registerUserDefinedFunction(new $.ig.CustomFunctions.SumTwo()); //load specific workbook $("#spreadsheet").igSpreadsheet("option", "workbook", workbook); } }
Note that CustomFunctions are prefixed to avoid any naming collisions with any of the predefined classes. Note also that writing a custom function can be rather involved since the arguments can be raw values, arrays or references and it’s really up to the function to properly handle all these things based on how it needs to function.You would likely need to look at the various members of the ExcelCalcValue class to see how to identify the value of the arg and how to extract information from it if it’s anything more involved than what I showed in the 2 examples in that fiddle.
I hope this would meet your scenario requirements. However, once the feature is implemented in the future version, it is strongly recommended to switch to using it instead of this workaround.
If you face any other issues - please let us know!
Thank you Alex.
Thank you for your response!
The information that our development team has provided according to this scenario is that using ‘ExcelCalcFunction’ is not recommended as it could result in unexpected behaviors if you create a type that conflicts with some of the internal types.
I have created a work item about exposing a ‘customFunction’ class that would be available in the future releases. I will attach the work item to this case so that you would be notified once it is resolved and the class is available.
Thank you for bringing this to our attention!
If you have other questions about the igSpreadsheet, do not hesitate to contact us again!
Best regards, Alexander