top | item 4085052

Show HN: Script Excel with Python

280 points| karamazov | 13 years ago |ironspread.com

61 comments

order
[+] smortaz|13 years ago|reply
This is great guys! We cooked up a similar thing called Pyvot (pivot). It's OSS/Apache - feel free to take/contribute. Cheers, smortaz@microsoft.

Video: http://www.youtube.com/watch?v=Oi3QKuFugWk&hd=1

edit - link to project: http://pytools.codeplex.com

[+] roryokane|13 years ago|reply
More specific link to Pyvot project: http://pytools.codeplex.com/wikipage?title=Pyvot.

My understanding of the difference between the links: Pytools in general lets you run Python programs in Visual Studio. Pyvot is a part of Pytools that lets any Python code on Windows (including code run in Visual Studio) connect to Excel.

[+] bmccormack|13 years ago|reply
I still have a soft spot for VBA, especially in Excel. I wrote a supply-chain management application in Excel+VBA that's still in production today. As comfortable as I am with VBA, I wouldn't mind in the least ditching it for Python, which makes writing routine methods trivial. Great work!
[+] karamazov|13 years ago|reply
Glad you like it!

We're also backwards compatible - you can keep running old VBA code, and write new scripts in Python.

[+] mwexler|13 years ago|reply
That's very clever. However, the ultimate integration of spreadsheet and Python has got to be ResolverOne (http://www.resolversystems.com/products/resolver-one/) It's a really amazing experience.
[+] dbecker|13 years ago|reply
I don't doubt that ResolverOne is a great experience... but so many businesses are wedded to Excel (and VBA).

I expect IronSpread will see much more use than ResolverOne because it will integrate into these offices more easily.

[+] steve8918|13 years ago|reply
What is the licensing for this? I couldn't tell whether this was free, if I had to pay, if it was open source, GPL, etc.
[+] karamazov|13 years ago|reply
It's a free beta. We'll be charging for it down the line, but you can use this however you like for now. (It's not open source, though.)
[+] dkhenry|13 years ago|reply
The big question I have is why would I use this instead of a real database. If i am not mistaken excel can hook up to ODBC sources and then I can just script things as I normally would using the database drivers.
[+] mattmanser|13 years ago|reply
Hoho, you ever sniffed the real world out there? Hell of a lot more excel junkies than programmers.
[+] karamazov|13 years ago|reply
If you want to script something quickly, Python is better; you also have access to all of Python's libraries (numpy/pylab, for example).

It depends on what you're doing, though.

[+] adorton|13 years ago|reply
Impressive. Would people I share a spreadsheet with need the plugin?
[+] karamazov|13 years ago|reply
Yes, they will.
[+] pneumatics|13 years ago|reply
This isn't necessary, you can have access to the full Excel COM API, with tab-completion, backwards-compatibility etc, for free with iPython and the makepy.py script.

http://stackoverflow.com/a/445961

Though I admit scripting Excel from Python should be easier to setup than it is.

[+] iamdave|13 years ago|reply
This is awesome! I plan to use this 100%. Sent it to a few other excel power users in my org, thank you for this
[+] pyxll|13 years ago|reply
If you want to call Python functions from Excel in the form of user defined functions, macros or menu functions (including macros bound to UI widgets and application events) you should take a look at PyXLL (www.pyxll.com).

This has been around for a couple of years now and actively maintained and supported, and is in use by many organisations already. It supports all versions of Excel from 2000 onwards, with some features only available in later versions (eg asynchronous functions are only in Excel 2010).

It uses cPython so all the standard libraries are usable.

Calling back into Excel is quite straightforward using win32com, and there are examples on the website that show how to do that.

With PyXLL you can write plain Python code that you can use outside Excel as well - so it's quite easy to write a library of functions that can be called from normal Python scripts as well as expose them to Excel at the same time.

I'm not sure what this project adds over what's already available but I'd be very interested to hear what other people's opinons are.

[+] nchlswu|13 years ago|reply
This seems really cool, but I'm admittedly not familiar with this area. How does this compare or supplement to Excel VBScript?
[+] karamazov|13 years ago|reply
Our goal is to replace VBScript. We'll have the same basic functionality, but using Python instead of VB, and with access to all of Python's libraries.

It's backwards compatible too - you can run VBA scripts and Python scripts at the same time.

[+] shazam|13 years ago|reply
That's funny, I just used xlrd and xlrt and had to convert about 100 files to 97-2003 workbooks
[+] fonzie|13 years ago|reply
This seems pretty great. Any plans for compatibility with Excel 2003 and 2007?
[+] karamazov|13 years ago|reply
We'll be compatible with 2007 in a day or two. We're not currently planning on supporting 2003, but this might change.
[+] il|13 years ago|reply
Any plans for OS X support?
[+] dbecker|13 years ago|reply
This solves a real business problem for a lot of people. I'm doubly impressed that it was done by a recent grad and someone still in school.

You guys have a bright future in front of you.

[+] AlexDanger|13 years ago|reply
This is great. I have to work with some very complex excel/VBA apps and this will be a breath of fresh air.

Is there anything out there that allows using C# to script/control excel?

[+] willyt|13 years ago|reply
Honest question; I havent tried to script xl or word for years. What is this doing that I couldn't do with IronPython or IronRuby?
[+] jaxn|13 years ago|reply
REALLY wish this was available for Mac.
[+] josteink|13 years ago|reply
Ask Apple for something equivalent of Windows COM+ and convince them they have a good reason for doing so once they stop laughing, and then you might have it.
[+] paduc|13 years ago|reply
Yep, me too!

Would it be possible to use this as a standalone (command line for instance) and not a plugin?

[+] bradleyy|13 years ago|reply
From a conversation with them, they are intending to charge around $2000/seat/month. This takes it out of the realm of possibility for me, but http://excel-dna.net/ looks like it will fit the bill with a little elbow grease.
[+] edwinyzh|13 years ago|reply
This is very interesting! Wrapping the entire Excel object model in Python must be a huge work.