Embedded/Python Services
Bojan Nikolic / BN Algorithms Ltd

[ExPy home] | [website home] | [BN Algorithms]

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. Although it is useful in its current form, it is intended primarily as a technology demonstrator. If you need to integrate Excel and Python we can help! For all enquiries please contact us at webs@bnikolic.co.uk.

News

  • (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

Entry points

There are two main entry points, functions ExPyScript and 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 x.float().

For more information see the Examples page

Download

You will also want to download the example spreadsheet -- see the examples page

Installation

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 ExPyXll.dll.

Licensing terms

Copyright statement of the ExPy Add-in

The Licensor of this work is BN Algorithms Ltd.

BY DOWNLOADING THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

  1. License Grant Subject to the terms and conditions of this License, the Licensor grants you a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to use this work on one computer.
  2. Restrictions
    1. You may not further distribute this work or any works derived from it
    2. You may not modify this work
  3. Warranties UNLESS OTHERWISE MUTUALLY AGREED BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
  4. Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Tweet