PyBites Module of the Week: Openpyxl - Automate Excel!

Bob, Tue 12 September 2017, Modules

automation, excel, first script, games, hacking, openpyxl, unix, vba

You probably remember your first script. I remember the joy of discovering how I could let the machine automate something for me. It still gets me excited everyday. I played a bit with openpyxl yesterday. I used it to hack an Excel game for which I first used a macro. Not particularly useful but a nice exploration of this module.

Hack the Game

I wondered how easy it was to redo an Excel (VBA) macro in Python. So I used one of my my first scripts to hack this Excel game. More info here including a story how I got into programming.

My first shot at it was xlrd because the game was in xls but it got messy. Not giving in easily, I asked Julian to save it to xlsx because I don't have MS Excel (thanks buddy).

Attacking the problem with openpyxl was a much greater experience. You can find the code here.

What was fun and beyond the initial Macro solution:

Conclusion

Lessons learned:

Call out to Finance / Excel folks

Let's do a challenge around this one! I logged an issue. If you have cool ideas what we can automate with Excel + Openpyxl update the issue. Thanks.


Keep Calm and Code in Python!

-- Bob

PyBites Python Tips

Do you want to get 250+ concise and applicable Python tips in an ebook that will cost you less than 10 bucks (future updates included), check it out here.

Get our Python Tips Book

"The discussions are succinct yet thorough enough to give you a solid grasp of the particular problem. I just wish I would have had this book when I started learning Python." - Daniel H

"Bob and Julian are the masters at aggregating these small snippets of code that can really make certain aspects of coding easier." - Jesse B

"This is now my favourite first Python go-to reference." - Anthony L

"Do you ever go on one of those cooking websites for a recipe and have to scroll for what feels like an eternity to get to the ingredients and the 4 steps the recipe actually takes? This is the opposite of that." - Sergio S

Get the book