Last active
October 23, 2019 12:46
-
-
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.
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 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