Author Topic: User Defined Function without arguments doesn't work  (Read 467 times)

pythonuser

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
User Defined Function without arguments doesn't work
« on: March 07, 2016, 07:29:01 PM »
https://www.pyxll.com/docs/index.html#writing-user-defined-functions-udfs

Based on website, the code snippet below should work but it doesn't

#
# Decorating a function with xl_func is all that's required
# to make it callable in Excel as a worksheet function.
#
@xl_func
def basic_pyxll_function_1(x, y, z):
    """returns (x * y) ** z """
    return (x * y) ** z

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 615
  • Karma: +14/-1
    • View Profile
Re: User Defined Function without arguments doesn't work
« Reply #1 on: March 07, 2016, 09:01:17 PM »
Hi,

apologies, that is wrong in the documentation.

To expose a function with no arguments you may provide an empty signature, eg

@xl_func("")
def func():
...

That example was accidentally included from the next release of pyxll, which will be released soon and doesn't require a signature.

Best regards,
Tony

pythonuser

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: User Defined Function without arguments doesn't work
« Reply #2 on: March 08, 2016, 04:50:25 AM »
Hi Tony,

thanks for the quick response. I tried

@xl_func("")
def test22(x, y, z):
    """returns (x * y) ** z """
    return (x * y) ** z

but it still doesn't work

returns #VALUE! in Excel

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 615
  • Karma: +14/-1
    • View Profile
Re: User Defined Function without arguments doesn't work
« Reply #3 on: March 08, 2016, 08:44:46 AM »
Hi,

that was for a function with no arguments , but that function has 3 arguments.

You need to use a signature like

@xl_func("int x, int y, int z: int")

This section in the docs may help you
https://www.pyxll.com/docs/index.html?highlight=xl_func#pyxll.xl_func

Also the examples should be in the package that you downloaded, and they should be the correct (it was only the ones on the website that were incorrectly referencing the new unreleased versions).

Best regards,
Tony