Spreadsheet Column to Index Conversion in Python

If you’ve ever had to dig down into specific columns of a spreadsheet with > Z columns you probably know how annoying it is to try to convert something like ‘AQ’ to the appropriate index (e.g. row[42]). Here’s a quick one-liner to convert a spreadsheet letter-based column to the equivalent zero-based index.

For example:

  • col2num(‘A’) -> 0

  • col2num(‘Z’) -> 25

  • col2num(‘BC’) -> 54

Author: Derek Springer

I write code & brew beer--if you ask nice I'll share some with you :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s