In Excel, dates and times are represented as numbers and require formatting to be applied for them to display as dates.
To manually format a cell as a date, select the cell and then change the Number Format for that cell from the Home tab (by default, the format will be "General").
PyXLL has the ability to set the number format automatically to save you having to do this manually, which we will cover in the next section.
Using PyXLL's "Cell Formatting" feature to automatically format dates
Formatting can be applied automatically when calling a PyXLL function using the "formatter" option to the @xl_func decorator.
For more information about cell formatting for worksheet functions (UDFs) see https://www.pyxll.com/docs/userguide/formatting/udfformatters.html
The following shows how a Python function that returns a date can set the cell formatting automatically using a formatter:
from pyxll import xl_func, Formatter import datetime as dt date_formatter = Formatter(number_format="yyyy-mm-dd") @xl_func(formatter=date_formatter) def get_date(): return dt.date.today()
Formatting pandas DataFrames
For worksheet functions (UDFs) returning pandas DataFrames containing dates, or requiring other formatting to be automatically applied, PyXLL has a DataFrameFormatter that can do this for you. This work in the same way as the code shown above, but can apply different formatting to the columns and index in the DataFrame.
For details and examples of DataFrame formatting please see the docs here https://www.pyxll.com/docs/userguide/formatting/pandasformatters.html.