Python API

Function decorator

@xllify.fn()

Register a Python function for Excel.

@xllify.fn(name, description="", category="", parameters=None, return_type="")
def my_function(...):
    ...

Arguments:

  • name (str) - Excel function name (e.g., "xllipy.MyFunc")

  • description (str) - Function description (defaults to docstring)

  • category (str) - Excel function category

  • parameters (list) - List of Parameter objects (optional)

  • return_type (str) - Return type hint (optional)

Example:

example.py
@xllify.fn("xllipy.Calculate", category="Math", description="Square a number")
def calculate(x: float) -> float:
    return x * x

Parameter metadata

Use Parameter objects for detailed parameter info:

Parameter fields:

  • name (str) - Must match function argument name

  • type (str) - "number", "string", "boolean", or "array"

  • description (str) - Parameter description

  • optional (bool) - Whether parameter is optional

  • default (any) - Default value

Type mapping

Excel Type
Python Type

Number

float

String

str

Boolean

bool

Range

List[List[Any]]

Empty cell

None

Arrays

Excel ranges become 2D lists:

Usage: =xllipy.SumRange(A1:C10)

Error handling

Raise exceptions to return errors to Excel:

Excel shows: #ERROR: Number must be positive

Type definitions

  • CellValue: A single Excel cell value — can be a number (float), boolean, string, or None (displays as empty cell)

  • Matrix: A 2D array of cell values (list of lists), where each cell is a CellValue

  • ExcelValue: Any value that can be returned to Excel (scalar, matrix, or pandas DataFrame)

Example returning a matrix:

Last updated