r/excel • 8 • 12d ago

Plugin Python embedded in Excel

Hi All,

This weekend for a bit of fun I built a free / source-available Excel add-in which hosts it's own Python runtime.

You can find a feature runtime and installation guide on the website:

https://sancarn.github.io/xll-python/index.html

fork it here: https://github.com/sancarn/xll-python

But here's an overview:

  • You can write user defined functions which execute like formula.
  • Returning a generator will make the result update every time it yield's a result.
  • You can write macros (e.g. reading / writing CSVs/databases from disk etc.)
  • There's an in-built IDE
  • You can debug formula in the IDE
  • There's a console/REPL where you can experiment with the available runtime
  • There's a package manager where you can install pip packages
  • There's a compiler so you can compile your own scripts into standalone .xll addins.

Hope you find this helpful! ~Sancarn

Edit: This project is AI:X. All code written by Astra & Sol 6.2; albeit with a lot of steering.

11 Upvotes

29 comments sorted by

View all comments

Show parent comment

1

u/decimalturn 11d ago

So the UDFs in an Excel file would always be able to find the addin needed for their evaluation as long as the addin is installed (and wasn't renamed)?

2

u/sancarn 8 10d ago edited 10d ago

I may have misunderstood what you were asking in the first place? The add-in presents 2 mechanisms to load python functions:

  1. Load them from a folder of scripts - Your colleague enables xll-python.xll and configures it to load your scripts from a worksheet functions startup folder.
  2. Load them from a packaged XLL - You send your colleague my-package.xll alongside the workbook. They enable that XLL in Excel. It already contains your Python code and runtime.

In general:

  • If you have an xlsm alone, the functions will not run, they will error with #NAME!.
  • If you have an xlsm with xll-python.xll added, the formulas will evaluate as desired, assuming the scripts are loaded.
  • If you have an xlsm with my-package.xll added, the formulas will evaluate as desired.

Edit: I could probably add something which allows one to embed the python scripts within a workbook... Sounds like a neat feature.

2

u/decimalturn 10d ago

Ok, that answers it.

Yeah, embedding is probably useful in case people can't be sent or download xll files.