I\'m looking for the opposite to this Q&A: Convert an excel or spreadsheet column letter to its number in Pythonic fashion.
or this one but in python How to conv
Here is a recursive solution:
def column_num_to_string(n):
n, rem = divmod(n - 1, 26)
char = chr(65 + rem)
if n:
return column_num_to_string(n) + char
else:
return char
column_num_to_string(28)
#output: 'AB'
The inverse can also be defined recursively, in a similar way:
def column_string_to_num(s):
n = ord(s[-1]) - 64
if s[:-1]:
return 26 * (column_string_to_num(s[:-1])) + n
else:
return n
column_string_to_num("AB")
#output: 28