Excelbind - Expose your python code in Excel¶
Excelbind is a free open-source Excel Add-in, that expose your python code to Excel users in an easy and userfriendly way.
Excelbind uses the Excel xll api together with an embedded python interpreter, so your python code runs within the Excel process. This means that the overhead of calling a python function is just a few nano seconds.
You can both expose already existing python functions in Excel as well as run python code directly from Excel.
To expose a python function in Excel as a user-defined function (UDFs) just use the excelbind function decorator:
import excelbind @excelbind.function def my_simple_python_function(x: float, y: float) -> float: return x + y
To write python code directly inside Excel just use the execute_python function:
=execute_python("return arg1 + arg2", A1, B1)
For more info on how to use Excelbind see the Getting Started section.
The code and Add-in available at GitHub.
- Excel 2007 or higher
- Python 3.5 or higher
If you want to build the project yourself you will also need:
- Visual Studio 2015 or higher
- CMake version 3.1 or higher (comes automatically with Visual Studio 2019)
- The pipenv python package installed
The project mainly piggybacks on two other projects:
- pybind11, which provides a modern C++ api towards python
- xll12, which provides a modern C++ wrapper around the xll api and makes it easy to build Excel Add-ins.
Excelbind basically ties these two together to expose python to Excel users.
A big source of inspiration is the ExcelDNA project. A very mature project, which provides Excel xll bindings for C#. Especially the semi-dynamic exposure of functions in the dll api using a thunks table is inspired by the way this is handled in ExcelDNA.
Excelbind also uses:
There are at least two other projects solving a similar problem to Excelbind:
- xlwings using a COM-server approach rather than using xll+an embedded interpreter.
- pyxll which is closed-source.