Skip to content

Instantly share code, notes, and snippets.

@goodwin64
Last active February 19, 2016 15:21
Show Gist options
  • Save goodwin64/4c7aecd6decb17b7b03d to your computer and use it in GitHub Desktop.
Save goodwin64/4c7aecd6decb17b7b03d to your computer and use it in GitHub Desktop.
def get_col_name(col):
abc = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
col_name = ""
while col > 0:
letter_index = col % 26
if letter_index == 0:
letter_index = 26
col -= 26
col //= 26
col_name = abc[letter_index] + col_name
return col_name.strip()
# uncomment lines below to output the result (delete "#" character)
# print(get_col_name(27)) # "AA"
# print(get_col_name(53)) # "BA"
# print(get_col_name(3702)) # "ELJ"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment