Skip to content

Instantly share code, notes, and snippets.

@vstoykov
Created January 4, 2013 14:33
Show Gist options
  • Save vstoykov/4452968 to your computer and use it in GitHub Desktop.
Save vstoykov/4452968 to your computer and use it in GitHub Desktop.
from string import letters
def calc_excel_column_number(string):
"""
Return number representing the column index in MS excel
A is the first column - return 1
B is the second column - return 2
...
Z is the 26th column - return 26
AA is the 27th column - return 27
...
etc.
"""
result = 0
for index, char in enumerate(reversed(string), 0):
result += (letters.index(char.lower()) + 1) * 26 ** index
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment