- Create codespace and point to https://github.com/shaofengzhu/learncodespace.git
- Run app.py
- Setup port forward using VS code as there is bug when using browser port forward.
- Configure local HTTPS reverse proxy for the port-forwrad as Excel requires HTTPS web site.
REM Only need to run office-addin-dev-certs once
npx office-addin-dev-certs install --days 365
REM The <port> is the port created by VS code port forward
npx office-addin-https-reverse-proxy --port 5500 --url http://localhost:<port>
-
Access
https://localhost:5500/functions.html
, click "Generate Manifest", then save the manifst file. -
Access
https://microsoft-my.sharepoint-df.com/
, create a Excel file -
Click "Insert" -> "Add-ins", in the dialog, click the "Manage My Add-ins" -> "Upload My Add-in", use the file you saved in step 1.
-
Now, a new Ribbon tab "Python" will show up. Please click "Python" -> "Show Taskpane", then in the taskpane, click "Register Functions with Excel".
-
Now, you could type in "=PYTHON.ADD(1,2)" in the Excel.
To add a new function, please go to codespace, stop run app.py, then modify the functions.py, add some code like
@customfunctions.customfunction(name = "MYMUL")
def mymull(x, y):
return x * y
Run the app.py
Now, go to Excel, click the "Python" -> "Show Taskpane", click "Register Functions with Excel".
Please cleanup the browser cache, and generate a new manifest.
Inside codespace, please
pip3 install -r requirements.txt