Skip to content

Instantly share code, notes, and snippets.

@f-ewald
Last active September 14, 2016 01:56
Show Gist options
  • Save f-ewald/1a20115d36144afd84aedbb129cda8b3 to your computer and use it in GitHub Desktop.
Save f-ewald/1a20115d36144afd84aedbb129cda8b3 to your computer and use it in GitHub Desktop.
Format column number Excel like to a cell letter
def get_column_letter(column_no):
"""
A = 0
Z = 25
AA = 26
AB = 27
BA = 52
:param column_no: The 0-based column index.
:return: The column as a combination of letters.
"""
stack = []
output = ""
while column_no > -1:
stack.append(column_no % len(self.alphabet))
column_no = column_no / len(self.alphabet) - 1
while len(stack) > 0:
output += self.alphabet[stack.pop()]
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment