User defined Calc function with Dot Notation?

I am wondering if it is possible to create a Calc Addin that has a Dot Notation that can be used in a calc function.

Cell A6 Formula Example.

=MyObj.myfunc1(B2, C5)

Cell A7 Formula Example.

=MyObj.myfunc2(A2)

Cell A7 Formula Example.

=MyObj.myfunc3(A3)

Is this kind or notation possible or must all function be declared separately?

An example would be how the AI object is used in Excel as demonstrated here.

In the example, the Excel add-in adds several functions with a common AI. name prefix.
Compare, Calc has several functions with the F. name prefix.

Fantastic. I now see there are a few of them an it is possible. I tried imlementing this in a few different ways with no luck. Does any know of an example or resource that could point me in the right direction?

What did you try and how did it fail?

In your AddIn.xcu using

<prop oor:name="DisplayName"><value xml:lang="en">MyObj.myfunc1</value></prop>

did not work?

Or letting your css::sheet::XAddIn::getDisplayFunctionName() return a name containing a dot did not work?

Or are we not talking about AddIn but actually a user defined function (UDF) in BASIC or Python, the question’s title and content doesn’t quite match. An UDF can not contain dots.

1 Like

OK I got it. One of those things that I was over thinkning.

<?xml version='1.0' encoding='UTF-8'?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry"
	xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="CalcAddIns"
	oor:package="org.openoffice.Office">
		<node oor:name="com.github.amourspirit.extension.MyObj" oor:op="replace">
			<node oor:name="AddInFunctions">
				<node oor:name="func1" oor:op="replace">
					<prop oor:name="DisplayName">
						<value xml:lang="en">MyObj.func1</value>
					</prop>
					<prop oor:name="Description">
						<value xml:lang="en">Function 1 example</value>
					</prop>
					<prop oor:name="Category">
						<value>Add-in</value>
					</prop>
					<node oor:name="Parameters">
					</node>
				</node>
				<node oor:name="func2" oor:op="replace">
					<prop oor:name="DisplayName">
						<value xml:lang="en">MyObj.func2</value>
					</prop>
					<prop oor:name="Description">
						<value xml:lang="en">Function 2 example</value>
					</prop>
					<prop oor:name="Category">
						<value>Add-in</value>
					</prop>
					<node oor:name="Parameters">
					</node>
				</node>
				<node oor:name="func3" oor:op="replace">
					<prop oor:name="DisplayName">
						<value xml:lang="en">MyObj.func3</value>
					</prop>
					<prop oor:name="Description">
						<value xml:lang="en">Function 3 example</value>
					</prop>
					<prop oor:name="Category">
						<value>Add-in</value>
					</prop>
					<node oor:name="Parameters">
					</node>
				</node>
			</node>
		</node>
	</node>
</oor:component-data>

IDL

#include <com/sun/star/uno/XInterface.idl>

module com { module github { module amourspirit { module extensions {
interface XMyObj
{
    string func1( );
    string func2( );
    string func3( );
};
 
}; }; }; };

Python

from __future__ import annotations
import uno
import unohelper
from com.github.amourspirit.extensions import XMyObj  # type: ignore

implementation_name = "com.github.amourspirit.extension.MyObj"
implementation_services = ("com.sun.star.sheet.AddIn",)


class MyObj(unohelper.Base, XMyObj):
    def __init__(self, ctx):
        self.ctx = ctx

    def func1(self) -> str:
        return "Func1"

    def func2(self) -> str:
        return "Func2"

    def func3(self) -> str:
        return "Func3"


def createInstance(ctx):
    return MyObj(ctx)


g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(createInstance, implementation_name, implementation_services)

1 Like