Dynamically registering function

Mar 31, 2012 at 11:52 PM

XL allows me to register functions during a call to the xll. I provide the c function name (which is looked up from the export table), the function alias to use in the spreadsheet and the arguements etc. XL returns a register id when I call xlfRegister.

I'd like to map many function alias's to one c function call and then dispatch the call to an appropiate python function. This way my user can write the function in python and add it to the spreadsheet with argument names and help.

Looking for ideas of how to determine which function alias call the xll's c function (i.e. determine the register id).

Can anyone help. Many thx.

Mar 31, 2012 at 11:58 PM

If you type =FUNCTION.NAME (without the open paren, args, close paren) in a cell you will get the register id. If you have the name of the function in your C code then you can get the register id by ExcelX(xlfEvaluate, OPERX("FUNCTION.NAME")).

Apr 1, 2012 at 12:18 AM

Thx. That's not quite what I need because I still need to know which function in the xl sheet actually called my c function.

E.g. let's say I have Fred and Joe both mapped to MyCDispatchFn then I need to know which of Fred or Joe called it so I can dispatch to the appropiate handler in Python.

I've seen this done in pyxll and ExPy through a single dispatch handler and through a run-time assigned handle in XLLOOP. I'd like know how to do the former.


Apr 1, 2012 at 12:24 AM

Why don't you just have Fred and Joe call the appropriate Python function? They know who they are already and you can call Python from C.

Apr 1, 2012 at 6:37 PM

Because then I couldn't add new functions on the fly - which is the essence of my question. I already know how to have a static set of functions available to xl from my add-in. But I'm looking for an elegant and extensible way of extending xl during an xl session. My stop gap is to pre-create say 500 wrapper functions but I've seen it done better but I can't figure how to determine the calling function from XL.

Apr 1, 2012 at 7:56 PM

See http://xllfunctional.codeplex.com/ for an approach to this.