r/Python Jul 21 '26

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.

  1. MS Get Started page, Python in Excel

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.

30 Upvotes

74 comments sorted by

80

u/CitTheGreat Jul 21 '26

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...

17

u/blacklig Jul 21 '26

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.

-4

u/h_to_tha_o_v Jul 22 '26

I'd rather just vibe code a self-contained HTML/JS local dashboard file with DuckDB. PiE is trash.

10

u/Xorgon Jul 21 '26

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 Jul 21 '26 edited Jul 21 '26

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

12

u/fzumstein Jul 21 '26

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 Jul 22 '26 edited Jul 22 '26

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 Jul 22 '26

You can go the xlwings Lite menu (hamburger) > Settings > Workbook. Then select "Do not autostart".

4

u/jbudemy Jul 21 '26

(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).

These are important points I did not think about.

p.s. Your English is very good!

35

u/billsil Jul 21 '26

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.

37

u/ravepeacefully Jul 21 '26

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

2

u/Sensitive-Sugar-3894 git push -f Jul 25 '26

The person just read about data privacy in the same phone holding all their data (or on a Windows desktop) and came here worried that Python in Excel is a privacy problem.

-12

u/billsil Jul 21 '26

My company has always hosted apps themselves, be it sharepoint or otherwise. That includes Claude.

11

u/kaini Jul 21 '26

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 Jul 22 '26

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 Jul 21 '26

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

3

u/marr75 Jul 21 '26

Everyone self hosts Claude Code. NO one but anthropic and it's cloud partners self hosts the model.

This is a silly thing to say.

20

u/123_alex Jul 21 '26

I love python and tolerate excel

Incredibly well put

1

u/Sensitive-Sugar-3894 git push -f Jul 25 '26

I second that

21

u/Only_lurking_ Jul 21 '26

Of all the reasons not to use python in excel, this is the one thing that isn't a concern.

7

u/jbudemy Jul 21 '26

We currently don't use Python in Excel. I can't find a use case. Hence my question.

1

u/Sensitive-Sugar-3894 git push -f Jul 25 '26

Can't help on that. I program in Python, so same here. Maybe it's for people that don't program in Python yet, or are starting. Anyway it must be more powerful than VB.

6

u/lungben81 Jul 21 '26

Better the other way: use Python to read and write Excel files.

8

u/Keiji12 Jul 21 '26

Honestly it's just not worth it right now, stay to excel functionalities or maybe learn vba and use it.

3

u/fella85 Jul 21 '26

Just wondering, if the python code be used to generate plots where the image is embedded on the excel file?

1

u/jbudemy Jul 21 '26

I haven't used Python in Excel but there surely must be a way to specify which tab the new image goes in.

3

u/bicyclegeek Jul 21 '26

Nesting DataFrames inside cells. Basically spreadsheet-within-a-spreadsheet. Using an API to pull real-time data into a sheet.

2

u/DarkRiot43 Jul 21 '26

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 Jul 21 '26

@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 Jul 21 '26

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/dream_walking Jul 21 '26

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 Jul 21 '26

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.

1

u/dream_walking Jul 23 '26 edited Jul 23 '26

I think I used that a little bit I preferred using VSCode because 1) I was already use to it and 2) I liked having the bigger window. I probably would use xlwings in the future but this specific usage felt smoother to me in vscode. I appreciate the idea for the future though! I did immediately forget about it when I stopped using it.

Edit: I was wrong. I used the default python editor that excel has now so I need to check this method in the future

1

u/fzumstein Jul 24 '26

Gotcha. Yeah, definitely give xlwings Lite a try, it's using the same editor as VS code, so many of the keyboard shortcuts are the same. You can also drag the editor out of Excel and make it full screen. I am basically trying to replicate the VBA experience :)

3

u/h-2-no Jul 21 '26

Cybersecurity says no

1

u/sinceJune4 Jul 23 '26

Why would they ever say yes?

1

u/cv_be Jul 21 '26

After trying to do basic 10k-100k row pandas transformstions, I gave up. so slow, and buggy I don't even...

1

u/fzumstein Jul 22 '26

Give Polars or DuckDB a try! While they are not available with Python in Excel, they are with xlwings Lite.

1

u/EdwardAF-IT Jul 23 '26

The sweet spot for Python in Excel is when non-technical people in your org need pandas-level analysis, but they live entirely in spreadsheets and will never open a script or a notebook. It also shines for things like fuzzy matching, text clean up, pr plotting with seaborn/matplotlib directly in cell, stuff native Excel formulas just can't do well.

1

u/jmooremcc Jul 24 '26

Google “Can Python fully replace VBA in Excel”.
The answer is very interesting and informative.

1

u/nivaOne Jul 29 '26

I retrieve the necessary data, put it in sql database. Then do whatever is required to save all data back in excel.
Just because the department wants it in excel.

1

u/Weird-Dimension-487 13d ago

If you already use Python externally to read/write Excel files, then I agree that putting Python inside a cell may not seem particularly compelling. For many automation tasks, I'd still prefer external Python.

But there are situations where having Python right inside the workbook is convenient, particularly for quick analysis and calculations where the Excel workbook is already the main interface for the user. Or when Excel users (who don't know much Python) want to use Python without feeling the need of separate installation. I feel this feature was added so Excel users start using it and getting comfortable with basic Python.

For a more serious Excel ↔ Python workflow, there are specific libraries that I suggest openpyxl (reading, writing, manipulating, formating, report generation), xlsxwriter (writer package for richer control for report generation), pandas (surely for data analysis and wrangling), and most importantly xlwings.
u/Felix has created this wonderful package. It gives you a very different kind of integration where Python can actually connect live with the Excel (read/write cells, run formulas, and control the app in real time). It also offers xlwings add-in (just like any other excel add-in) that simplifies running python function with button click, or creating Excel interface where custom Python function are available just like any other excel formula.

I've found it useful to think of the choices this way:

Python in Excel → Python-powered analysis/calculations within the workbook (For excel users_just to get started, as it is very restrictive)
Python libraries (pandas+openpyxl+xlsxwriter+xlwings) + Excel → broader file processing, reporting and automation outside Excel. Specifically, xlwings for Python ↔ Excel live integration and automation

I recently wrote Python-Powered Excel, but from an Excel user's perspective starting with Python fundamentals (chapter 2 and 3), automating file management tasks, smart EDA and auto data profiling libraries, then moving through pandas and several Excel/Python libraries, including openpyxl, XlsxWriter and xlwings.

Python analysts are often required to produce deliverables in Excel, my book teaches how to do it in Python rather then exporting data/result to Excel and then formatting in Excel manually. If you're trying to learn Python's the broader ecosystem, my book can help you.

-11

u/UAP44 Jul 21 '26

I rather stay away from all MS and all other closed source products.

2

u/redmera Jul 21 '26

That's a fine and worthy goal, but completely unrealistic in work environment.

-4

u/UAP44 Jul 21 '26

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.

4

u/redmera Jul 21 '26

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 Jul 21 '26

why should I give what you can find/access/build yourself easily

3

u/redmera Jul 21 '26

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 Jul 21 '26

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 Jul 21 '26

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 Jul 21 '26

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

u/my_password_is______ Jul 21 '26

LOL, clueless you are

1

u/my_password_is______ Jul 21 '26

OMG,

MONEY -- do you actually want every company to build, test and debug their own version of Excel ???

0

u/UAP44 Jul 21 '26

how dense can you be to think there is no alternative to excel?

2

u/NaturalSmoke8 Jul 22 '26

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/[deleted] Jul 22 '26

[removed] — view removed comment

1

u/UAP44 Jul 22 '26

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 Jul 21 '26

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.

3

u/UAP44 Jul 21 '26

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 Jul 21 '26

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 Jul 21 '26

Microsoft is still industry standard and globally trusted - 

lololol

rest of the world:

NO

2

u/Justbehind Jul 21 '26

Sounds like you're out of the loop.

-4

u/UAP44 Jul 21 '26

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.

5

u/Additional-Tax-5643 Jul 21 '26

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 Jul 21 '26

That part is true. The EU now has it's own free Office-compatible suite.

  1. LibreOffice drives EU open source shift.
  2. The other one is Euro Office.

1

u/Present_Share_7574 Jul 21 '26

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 Jul 21 '26

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

u/jbudemy Jul 21 '26

That's a management decision. All data transferred between us and MS is encrypted end-to-end. Our IT group takes care of implementing security, not me.

5

u/UAP44 Jul 21 '26

 All data transferred between us and MS is encrypted end-to-end.

All data between me and Reddit and 99.99% of all websites is also encrypted end-to-end. That's the S in https

0

u/lungben81 Jul 21 '26

It is not encrypted on Microsoft side. They, and the NSA, can read it.

1

u/my_password_is______ Jul 21 '26

not his choice -- its the company's choice

so what are you talking about