Python

Implementing functions in Python

Python code is always run as one or more external processes - it never runs embedded inside Excel.

You still bundle your Python scripts into the XLL for simple distribution:

  • Single file deployment: All Python code is bundled into the XLL

  • Automatic extraction: Python files are extracted to %LOCALAPPDATA%\xllify\<xllname>\ on first load

  • Automatic setup: Creates virtual environment (venv/) and installs dependencies

  • External execution: Python runs as a separate process, communicating with Excel via IPC

  • Development-friendly: You can edit the extracted Python files during development

Building an XLL

Prepare your Python files

Create your Python modules as normal:

main.py
# main.py
import numpy
import xllify

@xllify.fn("PYRAND")
def pyrand(data):
    return numpy.random.random()

Create requirements.txt (optional)

List your dependencies:

Build the XLL

Use the xllify CLI to embed your Python files:

Arguments:

  • --py-entrypoint: Required - The module to run (without .py extension)

  • --py-requirements: Optional - Path to requirements.txt to embed

What happens on first load

When Excel loads the XLL for the first time, xllify automatically:

1

Extracts Python files to %LOCALAPPDATA%\xllify\<xllname>\python\

2

Creates a virtual environment at %LOCALAPPDATA%\xllify\<xllname>\venv\

3

Installs xllify-python package into the venv

4

Installs requirements.txt dependencies (if bundled)

5

Starts the Python process automatically

This process takes 10-20 seconds on first load. Subsequent loads are instant since the environment is already set up.

Try it out

You can now enter =PYRAND() into a cell. A random number will appear in the cell.

Editing extracted Python files during development

After extraction, you can edit the Python files directly:

Changes take effect immediately after you save the Python file. If you change the function signatures, you will need to restart Excel.

circle-info

If you rebuild the XLL with updated Python code, you must delete the extraction directory to force re-extraction (see Re-extracting files after rebuilding).

Re-extracting files after rebuilding

If you rebuild the XLL and want to re-extract the embedded Python:

1

Close Excel

2

Delete: %LOCALAPPDATA%\xllify\MyAddin\

3

Reopen Excel (fresh extraction will occur)

Troubleshooting

chevron-rightPython files not extractedhashtag
  • Check %LOCALAPPDATA%\xllify\<xllname>\xllify.log for errors

  • Verify Python is installed and on PATH

  • Check disk permissions

chevron-rightEnvironment setup failedhashtag
  • Ensure Python is installed: python --version

  • Check that Python is on your system PATH

  • Try deleting the extraction directory and reloading

chevron-rightDependencies not installinghashtag
  • Check requirements.txt was bundled correctly: xllify MyAddin.xll main.py --py-requirements requirements.txt

  • Manually install: cd %LOCALAPPDATA%\xllify\MyAddin && venv\Scripts\pip install -r requirements.txt

chevron-rightNeed to update Python codehashtag
  • Rebuild the XLL with updated files

  • Delete: %LOCALAPPDATA%\xllify\MyAddin\

  • Reopen Excel (fresh extraction + setup)

Last updated