microsoft / python-in-excel

Python in Microsoft Excel
MIT License
490 stars 31 forks source link

Python user-defined functions #25

Open ahagmann83 opened 10 months ago

ahagmann83 commented 10 months ago

How can I define a Python function object? I tried to define a Python function in a PY Cell with def myfunc():, but it returned a NoneType Object.

ncalm commented 10 months ago

Are you able to use the function after defining it? In the same cell or another cell?

The type shown in the cell is the type of value in the cell.

A function can't be shown as a value really, unless executed. So even though it might be better to say "Function", I think it still works.

Try putting this under the function in the same cell: type(myfunc).__name__

keyur32 commented 10 months ago

You can do something like this to create shared logic.

=PY( def mysum(a, b): return a + b mysum(1,3)

As @ncalm mentioned about, you need to execute that function from within a Python formula. You can also make calls to that function from other python formulas, provided they come after the initial declaration in row-major-order.

One thing to note, is we will be allowing the Initialization pane for editing, so you will be able to store your functions there and call them.

mejrvs commented 8 months ago

When will that be released (editable initialization pane)?