8. A common misconception
• Quickstart is the beginning, not the end
• xlwings does not require the Python code in
the same directory as the Excel file nor
does it need to have the same name
• Reading the docs helps (although
improving the docs would, too ;-)
8
9. 3 Levels of Configuration
1. Workbook: xlwings first checks for a sheet called
“xlwings.conf” (needs to be activated after
quickstart)
2. Directory: Then it checks for the file “xlwings.conf”
in the same directory as the Excel file
3. Global/add-in: Finally, it checks for the global
configuration in ~/.xlwings/xlwings.conf (This is
what you edit & see in the add-in!)
9
10. Move and Rename the Python file
10
• Move demo.py to Desktop
and call it demo1.py
• Settings (they accept Env
Variables like %APPDATA%!):
• Change SampleCall (Alt-F11):
Sub SampleCall()
RunPython "import demo1;demo1.main()"
End Sub
12. ZIP files
A simple way to make deployment slightly easier if
you have more than 1 module.
12
import xlwings as xw
from utils import greeting
def main():
wb = xw.Book.caller()
wb.sheets[0].range("A1").value = greeting
demo.py
13. Installed Packages
• Create a package with your code
• You can upload it to an (internal) PyPI or to
a shared drive (or even install directly from
a Git repo url):
pip install shareddrivemypackge.tar.gz
• No need to change PYTHONPATH
13
14. Sample package
14
import os
from setuptools import setup
setup(name='demo',
version='1.0.0', # usually taken from source code
py_modules=['demo'])
python setup.py sdist
Create a setup.py file next to your demo.py:
This will create dist/demo-1.0.0.tar.gz that you can install like this:
pip install demo-1.0.0.tar.gz
Create the package:
15. Get rid of the add-in
15
xlwings quickstart demo --standalone
Once Python and package are installed, the Excel file
behaves like an ordinary xlsm file.
Or do File > Import File … and import xlwings.bas (from the xlwings
package location)
17. Freezers
• PyInstaller is the most popular option
• Note: It does not work with UDFs, only with
RunPython (macOS support pending)
• Advantages:
– Small size
– Source code is automatically compiled to pyc
and hidden away in the exe
17
18. RunFrozenPython
18
pyinstaller demo.pyFreeze it:
When adding unused packages to the excludes list in demo.spec,
you’ll end up with a bundle of only 20MB (uncompressed). Re-run:
pyinstaller demo.spec
Sub SampleCall()
RunFrozenPython ThisWorkbook.Path & "distdemodemo.exe"
End Sub
Place it somewhere and point RunFrozenPython to that path:
See: https://github.com/xlwings/xlwings-demo/tree/master/frozen
19. Code Obfuscation
• A lot of people seem to be obsessed with
code obfuscation
• Distributing pyc files instead of py files will
probably do the job most of the time
• The best option if that’s not enough is
probably a (commercial) package called
PyArmor: https://github.com/dashingsoft/pyarmor
19
21. Shared Drives
• You can install Python on a shared drive
• Simply point the interpreter in the config to the
one on the shared drive
• “Server-like” experience that makes deployment
and updating a piece of 🍰
• Only works for internal distribution
• It’s slower than a local installation but it’s being
used in practice
21
22. DropBox, OneDrive etc.
• You can place a frozen executable on your
DropBox folder or even install Python there
• Make use of env vars in your xlwings config:
– %USERPROFILE%Dropbox
– %ONEDRIVE% or %ONEDRIVECOMMERCIAL%
22
24. Goal
24
• Zero Python knowledge required
• Zero configuration (installer & workbook)
• Works for both UDFs and RunPython
• Works for external distribution
• Easy way to deploy updates
• Cross-Platform (macOS coming soon…)
25. Embed Python code
xlwings PRO allows
you to ship your
Python code inside
the Excel file, much
like VBA.
This can be a huge
plus when rolling out
updates as end users
only have to replace
the Excel file.
25