How do I run commands from Excel ?

My first blog post – I started my business just over a year ago and always promised myself to blog about what I do. A year later I look at the website and it feels pretty empty, so hopefully from now on I can post more about what I do πŸ˜‰πŸ‘

You may or may not know that I spend a lot of time in the Tableau Community Forums (a lot !!!), I also credit the Forums with one of the best ways to increase your Tableau knowledge by ….

  1. Checking questions that have been answered, and read through the answer; download the workbook; etc… to learn how to answer that question, AND
  2. Answering questions that don’t have an answer – even if you don’t answer the question correctly someone else will correct you.

BOTH options are a WIN – you learn more by participating in the Forums.

So today I have some spare time (it’s the weekend, it’s pouring rain outside and the Australian Formula1 Grand Prix broadcast is starting soon 🏎 ) and I notice this post on the Forums:

My initial reply was just a vanilla comment about maybe using a batch file or Python. Really I was just wanting to reply because the post was over a month old with no replies and everyone deserves a reply 😊 (hot tip: the Crows Nest is a great way to find these “unanswered posts” and there’s some tricky questions in there to challenge your Tableau knowledge).

But as soon as I posted my reply I thought “that would be really simple in Python” (I’ve never actually read Automate the boring stuff with Python but I love the title), so some quick google searches and I found enough bits to write some Python code. I created a simple spreadsheet to mimic the spreadsheet above (OK, so a quick “dir” and “dir” with an additional path will serve the purpose) …

Just a few simple commands that will work

And some Python code to read the spreadsheet, join the command and parameter together and get the output …

Very simple, quite a few opportunities to make it better if required

And voila, a script that you can run to do a list of any valid DOS command that exists in the spreadsheet (maybe I can use this in the future as well πŸ˜‰)

Yes, the script is very simple and there’s a few places where it could be improved, but in less than 30 minutes the forum post is answered and I’ve learned a bit more about Python 😎

Download the zip file if you want the files as templates for improvement

And the forum post that started all this is here

Leave a Reply

Your email address will not be published. Required fields are marked *