Created
May 21, 2018 17:29
-
-
Save rdapaz/443e058223ade993ffa8c0fe54ba58c6 to your computer and use it in GitHub Desktop.
Getting column name from column number in Excel
This file contains hidden or 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 column_name(iVal): | |
retVal = None | |
if iVal <= 26: | |
retVal = chr(64+iVal) | |
else: | |
m = int(iVal/26) | |
n = iVal - m*26 | |
if n==0: | |
m = m-1 | |
n = 26 | |
retVal = '{}{}'.format(column_name(m), column_name(n)) | |
return retVal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment