Last active
September 14, 2016 01:56
-
-
Save f-ewald/1a20115d36144afd84aedbb129cda8b3 to your computer and use it in GitHub Desktop.
Format column number Excel like to a cell letter
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
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