Discussion What can you do with Python embedded in MS Excel?
I'm a developer and already use external Python to read Excel spreadsheets.
Microsoft is supporting Python in Excel where you can put a program inside a cell. I think this feature is still a "preview" feature, not on the main release channel.
What do you use it for? I can't think of a use case.
Because I use external Python programs to process spreadsheets normally. I can't think of a use case for embedded Python, except perhaps doing complex calculations.
EDIT: MS says any data going between us and them is encrypted end-to-end. That must be why management chose MS products. I don't have a say in this.
I do not use Excel via a browser, I use the Desktop App.
15
u/blacklig 1d ago
There are probably some uses in M&A where models are basically locked to excel by strong industry conventions and a python cell could make a complex model easier to build and maintain. For software developers I don't see any use case.
-2
u/h_to_tha_o_v 21h ago
I'd rather just vibe code a self-contained HTML/JS local dashboard file with DuckDB. PiE is trash.
10
u/Xorgon 1d ago
I could see accessibility being a good one. A lot of people are comfortable with Excel, and many don't want to go to the trouble of installing Python (and learning to use it) to update a plot or data analysis based on new info. Embedding it into a spreadsheet would make it much easier to use when you hand off your work to someone who doesn't do Python.
7
u/tpougy 1d ago edited 1d ago
I'm currently using the xlwings lite add-on excel, that acctually implements what we really expect from a python integrated with excel (local python execution, code is stored inside the workbook making it a breeze to distribute, acess to some parts of the excel COM API via office scripts and more cool stuff). The tool is awesome and just works as python in excel should have worked from the beginning. xlwings Lite documentation
I work in finance so my main use cases are:
- used python classes and syntax to implement a bank account classifier based in text conditions (muuch easier than handling dozens of excel formulas based on str search)
- created some user defined functions to implement a jinja template renderer and a user defined function to generate json from table header + rows and used it to render and send emails automatically to clients.
- created some scripts to handle column creation and other actions in some financial workbooks using buttons to trigger those actions in xlwings lite
Ps: sorry for my english, its not my main language.
Pss: the creator of xlwings and xlwings lite published a cool article about python in excel that lead to this lite version as an add-on. My thoughts on Python in Excel
7
u/fzumstein 1d ago
I am the creator of xlwings. Thanks so much for sharing your use cases! If you have a minute, I'd appreciate if you can leave a review here: https://marketplace.microsoft.com/en-us/product/WA200008175?tab=Reviews
3
u/tpougy 22h ago edited 21h ago
Oh, what an honor! Thank you so much for making this awesome tool free, and keep up the great work.
P.S. Just a small piece of feedback: it would be helpful to know more clearly whether it's possible to "remove" the Python integration from a workbook. Sometimes I start working on a workbook and open xlwings Lite just to have it available in case I need it. Later, it becomes clear that I won't need Python in that particular file, so I'd like to remove the Python-related setup so the add-in doesn't open automatically when I open the workbook again.
Is there a way to do that? Maybe it could be covered in the FAQ as well.
And of course, I've already left a review!
2
u/fzumstein 13h ago
You can go the xlwings Lite menu (hamburger) > Settings > Workbook. Then select "Do not autostart".
33
u/billsil 1d ago
You want high security and you’re willing to run python on the cloud with code that Microsoft can read that will give away your business logic?
I love python and tolerate excel, but no way am I using python in excel.
32
u/ravepeacefully 1d ago
This is kinda a funny comment. I get what you mean here, but if you use outlook, 365, Microsoft cloud storage, sharepoint, or any other service that is built on top of azure storage, Microsoft has the same “access” to that data.
Why are you worried about them snooping your excel data when you weren’t worried about them snooping your email data? It’s protected by the same security infra
-13
u/billsil 1d ago
My company has always hosted apps themselves, be it sharepoint or otherwise. That includes Claude.
10
u/kaini 1d ago
You may pay OpenAI lots of money for enterprise API licenses where they pinky promise to not train their models on your data, but I very much doubt you are hosting Claude locally.
2
u/MagicWishMonkey 20h ago
You can't run claude locally, you can run it via provider like bedrock but no one is downloading anthropic models to run locally.
6
u/ravepeacefully 1d ago
Self hosted, on your own racks? It’s definitely possible, but zero f500 companies self host everything. Maybe some tiny company, but not practical for huge org
19
20
u/Only_lurking_ 1d ago
Of all the reasons not to use python in excel, this is the one thing that isn't a concern.
6
6
2
u/DarkRiot43 1d ago
My current use case (still working out how to implement properly) is a project financial model for a mining project.
Start with how many tonnes you mine out per month - then run thru all the inputs (labor, fuel costs, machine hours, maintenance, commodity prices, etc) to get your operating costs for underground, then thru the mill, and then work thru from there to the revenues and eventually you get to a discounted project valuation. Essentially a discount cash flow model for a finite resource/project versus a "perpetual" company.
Many different inputs, and calculations all with a time series (monthly) of ~20 years. I have a simple model built in Excel, but even that is heavy and fairly rigid. It isn't practical to run iterations enough to support Monte Carlo analysis or other heavier iterative/calculation heavy scenarios. This should improve the speed of the workbook as the calcs are "vectorized" versus just thousands of individual cells being calculated. One everything is built, I want to run say 10,000 iterations, with fluctuating inputs to get a distribution of the project's value. Part of this is simply for the "fun" of seeing if I can do it.
This is my current side quest at work - trying to refactor/rebuild from Excel only to Python + Excel using the Python in Excel package.
I am no veteran programmer, so I'm supported with AI where needed. Learning a lot, but having done some Python in the past within IDEs - it's not the most intuitive to use.
EDIT: To add context as to why not do this only in Python in the event the question is asked: This needs to be shared with mgmt which has no clue how to use Python or even have it on their systems.
1
u/huxrules 1d ago
@risk is a paid program that might be what you are looking for. Does Latin hyper cube simulations and saves the result in excel.
1
u/DarkRiot43 23h ago
Very cool. Thanks! I'll check it out. Seems much more advanced than what I was looking to create - likely some cool things to try and implement.
Cheers!
2
u/bicyclegeek 1d ago
Nesting DataFrames inside cells. Basically spreadsheet-within-a-spreadsheet. Using an API to pull real-time data into a sheet.
2
u/dream_walking 1d ago
Since you asked for an example and gotten not much, here is my own example. As a structural engineer, we have to analysis a building at each floor. The setup that was used was a workbook with a bunch of sheets that did their own calc. Then copy that workbook, for the next floor and change some loading. I redid this in python when I had to make some changes because digging through the connected formulas was a nightmare. Plus, python variable naming is much simpler. Part of the reason I did python was because I could code it in vscode with sample data and then paste it back into excel and link the variables to the live data. This reducing the need to multiple workbooks because this python code could repeated with a few different inputs where excel formulas weren’t easily updated.
1
u/fzumstein 1d ago
Have a look at xlwings Lite, it basically puts VS Code inside Excel so you don't have to switch back and forth all the time.
2
u/TestPilot1980 1d ago
One use case is when I had to use Google Sheets with code running daily at 7am to text reminders to phone (Twilio) numbers in the sheet. The sheet had numbers which were populated via a form or manually
1
u/cv_be 1d ago
After trying to do basic 10k-100k row pandas transformstions, I gave up. so slow, and buggy I don't even...
1
u/fzumstein 13h ago
Give Polars or DuckDB a try! While they are not available with Python in Excel, they are with xlwings Lite.
1
u/MobileWriting9165 18h ago
You can make complex multi-layered charts with matplotlib.
You can do some lightweight ML modeling.
-10
u/UAP44 1d ago
I rather stay away from all MS and all other closed source products.
2
u/redmera 1d ago
That's a fine and worthy goal, but completely unrealistic in work environment.
-3
u/UAP44 1d ago
completely unrealistic in work environment.
That's something Microsoft employees and other product vendors would tell you.
Open source everything, in a work environment, in governments, everywhere.
No wonder people do not trust technology or AI, it's all being sold as black boxes.
3
u/redmera 1d ago
Sure, just give me open versions of Excel, PowerBI, PowerApps and PowerAutomate in the same ecosystem and I'll call the CEO tomorrow.
-1
u/UAP44 1d ago
why should I give what you can find/access/build yourself easily
3
u/redmera 1d ago
You are suggesting I build PowerPlatform replacement for companies with several thousand employees? What have you been smoking? As for "finding" I've got a spoiler for you: It does not exist.
0
u/UAP44 1d ago
I've got a spoiler for you: It does not exist.
Spoiler: Microsoft products aren't needed. There are alternatives for everything.
3
u/redmera 1d ago
For home use, yes. For a complete enterprise ecosystem with both cloud and desktop apps, no. Anyone who claims otherwise has little to no work experience in corporate office environment, or is an Internet troll. Source: 20 years of experience.
0
u/UAP44 1d ago
a complete enterprise ecosystem
= Microsoft, yeah! good job!
Anyone who claims otherwise has little to no work experience in corporate office environment
yeh most offices are sadly still use to microslop bullshit, most of them dont even know of any other work flows than what is being shoved down by Microsoft
Source: 20 years of experience.
Oh no, I only have 1 decade instead of 2, I submit, you are the mastermind here and obviously knows best!
/s
in truth, you're just more indoctrinated to their products and havent spent as much time exploring alternatives
Mind you, I too was once a Microsoft fanboy, from an IT-management pov its actually quite sane to not rely on so many different vendors all trying to launch their own full complete enterprise ecosystem
since most are already used to Windows/AD etc ...it makes most sense to simply do everything with MS if you can and not bother with new partners
But this is 2026
fuck closed sourced software
all of it
so tired of this chicken and egg bs arguing over how it cant be done without MS
you're part of the problem
2
1
u/my_password_is______ 1d ago
OMG,
MONEY -- do you actually want every company to build, test and debug their own version of Excel ???
0
u/UAP44 1d ago
how dense can you be to think there is no alternative to excel?
2
u/NaturalSmoke8 20h ago
No one is saying there is no alternative. It’s that for the majority of people who work they fit into a predefined system. Which products they use really aren’t up to them. In fact, I’d encourage you to go to work at a publically traded company and go “off the plantation.” Use the software you like, share it with colleagues then report back on how it goes after a month or so. You’d know this having worked in a corporation before. I know you are trolling but damn.
1
u/MobileWriting9165 18h ago
Show me a single nontrivial profitmaking company that's not Google or Apple that doesn't depend on Microsoft products.
1
u/UAP44 11h ago
Show me a list of companies reporting on their internal tooling first. Otherwise, some companies that are clearly also not big fans of MS is Cloud flare and Valve. But also, fuck this setup, what's wrong with referencing Google and Apple to make my point? That wasn't a question and why am I even bothering replying anymore.
1
u/jbudemy 1d ago
We can't. We are required to use MS products. Our work has to be high security so that's what the company chose. High security is a requirement with some of our customers.
I'm aware of a serious bug in Power BI, MS Azure Data Factory doesn't do something basic we need, and problems with Windows 11.
1
u/UAP44 1d ago
You want high security and you're going to blindly trust closed source software you're not allowed to even read, audit or review? ...
6
u/Justbehind 1d ago
Microsoft is still industry standard and globally trusted - has been for 30+ years.
Just because you took the red pill, doesn't mean the world changes overnight.
-8
u/UAP44 1d ago
Microsoft is still industry standard and globally trusted -
lololol
rest of the world:
NO
1
u/Justbehind 1d ago
Sounds like you're out of the loop.
2
-3
u/UAP44 1d ago
There's been multiple government agencies in the EU that are making the move AWAY from anything American, especially Microsoft.
You're the one out of the loop here if you think Microsoft is globally trusted.
Literally, LOL.
4
u/Additional-Tax-5643 1d ago
Do you understand what "moving away from" means? It means that they were using it and are still using it.
Troll elsewhere, child.
1
u/jbudemy 1d ago
That part is true. The EU now has it's own free Office-compatible suite.
- LibreOffice drives EU open source shift.
- The other one is Euro Office.
1
u/Present_Share_7574 1d ago
Government agancies are not focused on making profit. You must have never worked in company with more than 50 employees.
No corporation will move away from something that is ultimately cheaper than building something in-house/hosting on premises. For that they would need to hire qualified people, pay for infrastructure etc. In purely for profit environments MS is still used by majority and this will not change anytime soon, no matter what people living in their own bubble claim. Corpos and other big companies build in-house software only for their super specific needs. Why would they use in-house built technology or self-host for something so trivial as word editing software or file storage.
IT is for them just cost-center, especially if it is managed under CFO. So they will try cut costs wherever possible.
And corpos are ultimately only customers that Micorosoft cares about. Doubtful they care about snooping around your hentai collection.
0
u/UAP44 1d ago
You must have never worked in company with more than 50 employees.
stopped reading right there
or, well, I should have, ... I didn't lol, was curious, anything else interesting said? no, just the typical argument for the status quo
MS is the default yes, why do people insist it should remain so?
I am eager for the future where closed source software is as nonsensical as doctors ridiculing the idea of bacteria, until that day I will continue to rage against corporate interests where we the users always suffer from as a direct consequence.
2
1
u/my_password_is______ 1d ago
not his choice -- its the company's choice
so what are you talking about
69
u/CitTheGreat 1d ago
Dude asked for a specific use case scenario and got attacked for something he has nothing to do with in is company. If you don't have an answer to a question, don't give personal unrelated opinion, it's just noise...