Created
January 4, 2013 14:33
-
-
Save vstoykov/4452968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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