Sometimes you will want to write a function where one or more of the parameters could be any one of a number of types. For example, a parameter might be a string in some cases or a date in others.
You can use the "var" type to specify that a function parameter could be any type, for example:
from pyxll import xl_func
@xl_func("var x: var")
def py_func(x):
# x could be any type
return ...
But, now "x" will be passed as the closest Python type to the Excel type. Excel stores dates as numbers, and the only thing that makes them dates in Excel is the cell formatting. When a date is passed via the "var" type it will come in to Python as a float. What if you now want to convert that float to a Python date or datetime?
You can use pyxll.get_type_converter to convert from one type to another using PyXLL's type converters (including your own registered custom type converters). For example,
from pyxll import xl_func, get_type_converter
@xl_func("var x, bool is_date: var")
def py_func(x, is_date):
if is_date:
var_to_date = get_type_converter("var", "date)
x = var_to_date(x)
...
This way you can write Python functions that accept different types and convert them to the type you want.