Skip to content

Instantly share code, notes, and snippets.

@surskitt
Last active December 24, 2015 18:59
Show Gist options
  • Save surskitt/6846488 to your computer and use it in GitHub Desktop.
Save surskitt/6846488 to your computer and use it in GitHub Desktop.
Converts an absolute column number to an excel column notation (A - XFD).
def col2letter(col):
if col > 0 and col <= 16384:
a1 = chr((col / 26 ** 2) + 64) * (col > 26 ** 2)
a2 = chr(((col % 26 ** 2) / 26 - (not col % 26)) + 64) * (col > 26)
a3 = chr((col % 26 + (26 * (not col % 26))) + 64)
return ''.join((a1, a2, a3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment