ONLYOFFICE / sdkjs-plugins

The add-ons for ONLYOFFICE Document Server and ONLYOFFICE Desktop Editors.
https://www.onlyoffice.com
Apache License 2.0
136 stars 134 forks source link

How to create a custom function in a functionRegistry #146

Open dmziryanov opened 3 years ago

dmziryanov commented 3 years ago

How to create a custom simple function, for a example foo() to insert in a cell '=foo()'? Is it possible without modification the source code?

ShockwaveNN commented 3 years ago

@askonev Please take a look

askonev commented 3 years ago

Hello, @dmziryanov Perhaps the use of our macros will help you to solve your problem. Example. Let's find with the help of macros the minimum value from the range of cells from B1 to B3.

Screen record from 2021-03-05 11 20 43

Script

(function()
{
oWorksheet = Api.GetActiveSheet();
oWorksheet.GetRange("A1").SetValue("=min(B1:B3)");
})();
dmziryanov commented 3 years ago

Plugins and macroses are great to help, but the best way to solve our problem is to push a custom function (e.g. foo(A2, B2)) through the table and fill certain cells.

This function is impossible to create like combination of the existing functions because it should take data from REST API with token authorization and should be defined in such way that cell analizer could evaluate it like other functions (like MS Excel could evaluate custom function with custom calculations defined in macros).

As far as I could understood this is imposible without modification ONLYOFFICE/core

askonev commented 3 years ago

@dmziryanov Yes, you're right about the fact that adding such functionality will require a modification ONLYOFFICE/core. However, how do you look at the analog of the LAMBDA functions. At the moment we do not have this functionality, but we will think about its implementation.

kayanme commented 3 years ago

I can suggest more straightforward case to discuss. We have a need to call a REST web-service and then store the result in the target cell. Is there a way to make such an operation except the macro above (i.e. SetValue...)? F.e. some built-in function for an external service call?