I have the following python function (for the purpose of testing user defined functions):
def add_number(x,y):
z = x+y
return z
It is stored in the following document:
/home/MYUSERNAME/.config/libreoffice/4/user/Scripts/python/python_functions_for_lo_calc.py
It is referenced by the following Libreoffice basic macro to generate a user defined function for Calc:
Function add_number(x,y)
Dim myScript as Object
myScript = ThisComponent.getScriptProvider().getScript(“vnd.sun.star.script:python_functions_for_lo_calc.py$add_number?language=Python&location=user”)
add_number = myScript.invoke(Array(x,y), Array(), Array())
End Function
When I start a new Calc document and use the formula in a cell (e.g. C3) =add_number(2,2) it will give the correct answer of 4.
When I save the Calc document and re-open it from within Libreoffice (that is by going ‘File’ → ‘Open’ and the navigate to the document it also works.
But, if I open the document from the system file manager (in my case using nemo in Cinnamon in Debian 12)
I get the following error message:
Basic Runtime error. Property or method not found: getScriptProvider.
It then highlights the following line:
myScript = ThisComponent.getScriptProvider().getScript(“vnd.sun.star.script:python_functions_for_lo_calc.py$add_number?language=Python&location=user”)
What is going wrong? I am using the default Libreoffice in Debian 12. I get the same problem using Linux Mint. I have also downloaded the latest 24.3.2 from Libreoffice and installed on Debian 12 and I get the same problem.
I am guessing this is due to Libreoffice components not initialising in time before being called by the function.