Skip to content

Instantly share code, notes, and snippets.

@egeulgen
Last active October 23, 2019 12:46
Show Gist options
  • Save egeulgen/ca0cfb0fe928fc075deff0ccb68f4745 to your computer and use it in GitHub Desktop.
Save egeulgen/ca0cfb0fe928fc075deff0ccb68f4745 to your computer and use it in GitHub Desktop.
Finds excel-style column name for a zero-based index. e.g. 3 >> D, 26 >> AA, 28 >> AC etc.
def indexExcelColumnFinder(self, idx):
''' Find Excel-style Column Name
Given a 0-based index 'idx', returns the
corresponding Excel-style column naming
(eg. 3 >> D, 26 >> AA, 27 >> AB etc.)
'''
excelColumnNameList = []
alphabet = map(chr, range(65, 91))
if idx < 26:
excelColumnPlace = alphabet[idx]
return excelColumnPlace
else:
letterCounter = 26
for letter in alphabet:
for letter2 in alphabet:
if letterCounter == idx:
excelColumnPlace = letter + letter2
return excelColumnPlace
letterCounter += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment