These decorators are used to expose Python functions to Excel as worksheet functions, menu functions and macros.
xl_func
([signature][, category="PyXLL"][, help_topic=""][, thread_safe=False][, macro=False][, allow_abort][, volatile=False][, disable_function_wizard_calc=False][, disable_replace_calc=False][, name][, auto_resize=False][, hidden=False][, transpose=False][, recalc_on_open][, formatter=None][, nan_value][, posinf_value][, neginf_value])xl_func is decorator used to expose python functions to Excel. Functions exposed in this way can be called from formulas in an Excel worksheet and appear in the Excel function wizard.
Parameters: |
|
---|
Example usage:
from pyxll import xl_func
@xl_func
def hello(name):
"""return a familiar greeting"""
return "Hello, %s" % name
# Python 3 using type annotations
@xl_func
def hello2(name: str) -> str:
"""return a familiar greeting"""
return "Hello, %s" % name
# Or a signature may be provided as string
@xl_func("int n: int", category="Math", thread_safe=True)
def fibonacci(n):
"""naive iterative implementation of fibonacci"""
a, b = 0, 1
for i in xrange(n):
a, b = b, a + b
return a
See Worksheet Functions for more details about using the xl_func decorator, and Array Functions for more details about array functions.
xl_menu
(name, menu=None, sub_menu=None, order=0, menu_order=0, allow_abort=None, shortcut=None)xl_menu is a decorator for creating menu items that call Python functions. Menus appear in the ‘Addins’ section of the Excel ribbon from Excel 2007 onwards, or as a new menu in the main menu bar in earlier Excel versions.
Parameters: |
|
---|
Example usage:
from pyxll import xl_menu, xlcAlert
@xl_menu("My menu item")
def my_menu_item():
xlcAlert("Menu button example")
See Menu Functions for more details about using the xl_menu decorator.
xl_macro
([signature][, allow_abort][, name][, shortcut][, nan_value][, posinf_value][, neginf_value])xl_macro is a decorator for exposing python functions to Excel as macros. Macros can be triggered from controls, from VBA or using COM.
Parameters: |
|
---|
Example usage:
from pyxll import xl_macro, xlcAlert
@xl_macro
def popup_messagebox():
"""pops up a message box"""
xlcAlert("Hello")
@xl_macro
def py_strlen(s):
"""returns the length of s"""
return len(s)
See Macro Functions for more details about using the xl_macro decorator.
xl_arg_type
(name, base_type [, allow_arrays=True] [, macro=None] [, thread_safe=None] [, typing_type=None])Returns a decorator for registering a function for converting from a base type to a custom type.
Parameters: |
|
---|
xl_return_type
(name, base_type [, allow_arrays=True] [, macro=None] [, thread_safe=None] [, typing_type=None])Returns a decorator for registering a function for converting from a custom type to a base type.
Parameters: |
|
---|
xl_arg
(_name[, _type][, _label][, _description][, **kwargs])Decorator for providing type information for a function argument.
This can be used instead of providing a function signature to xl_func
.
Parameters: |
|
---|
xl_return
([_type=None] [, **kwargs])Decorator for providing type information for a function’s return value.
This can be used instead of providing a function signature to xl_func
.
Parameters: |
|
---|