We recommend expy -> xlwings
NOTE: For all new projects we recommend open source xlwings see e.g., the examples below. We are able to offer implementations and extensions of xlwings. If you want to read about ExPy, one of the early open-source projects in this area, see below.
XLWings in action examples:
- Using PyTorch from Microsoft Excel
- Principal Component Analysis in Excel
- Bayesian robust linear regression in Excel
Expy Python interpreter Add-in
The ExPy add-in allows easy use of Python directly from within an Microsoft Excel spreadsheet, both to execute arbitrary code and to define new Excel functions. Features:
Based on the standard Python interpreter (i.e., not IronPython or other alternatives). Therefore it is fully compatible with all standard Python extensions
Easy installation – just unpack and add the DLL to Excel as an Add-In. No registry modification, no installation to system directories
Define new Excel function at run-time directly from the Excel worksheets
No COM - based on the pure C-language Excel API
The ExPy add-in is made available to you free-of-charge on this web-site, under the licensing terms detailed below. If you need to integrate Excel and Python we can help! For all enquiries please contact us at firstname.lastname@example.org.
Source code is now available on this page
(V0.3+) NumPy is included as is a facility to transform NumPy arrays to cell ranges. This for example allows access to NumPy functionality like random numbers, FFTs, eigenvalue calculations and singular value decompositions
There are two main entry points, functions
ExPyEvalSS. Both of these functions take a single argument, which is a string to be executed. The difference between them is that
ExPyScript is designed for execution of a sequence of Python statements for their side-effects, while
ExPyEvalSS is designed for execution of a single Python statement for its return value.
The execution of statements is carried out like in an interactive Python interpreter, i.e., they are evaluated in the
__main__ namespace. The interpreter state is continuous for the duration the running Excel session. Restarting the Excel session leads to a restart of the Python interpreter .
The return values of functions are passed back to Excel program as strings.
For more information see the Examples page
Reflection of Python functions in Excel
The ExPy Add-in also allows for any Python functions to be directly accessible from the worksheet. This facility is implemented using the
ExPy.register function which takes two arguments: the name of the function to be made available from Excel and the number of arguments that this function will take.
All arguments from Excel are passed into Python as
xll.XLOper types which the Python function needs to convert to a more specific type. Currently, only string and number types are supported. To convert an
XLOper object to a string you can simply use the
str(x) function. To convert an XLOper to a floating point number, the member function
float should be used, i.e., if
x is of
XLOper type then the call should be
For more information see the Examples page
You will also want to download the example spreadsheet – see the examples page
Simply unpack the
.zip file and then register
ExPyXll.dll as an Excel Add-in. The remaining files that come in the
.zip file must remain in the same directory as
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the NumPy Developers nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.