python - Convert a number to Excel’s base 26 - Stack Overflow
stackoverflow.com › questions › 48983939Feb 26, 2018 · def toBase26(x): x = int(x) if x == 0: return '0' if x < 0: negative = True x = abs(x) else: negative = False def digit_value (val): return str(chr(int(val)+64)) digits = 1 base26 = "" while 26**digits < x: digits += 1 while digits != 0: remainder = x%(26**(digits-1)) if remainder == 0: remainder += 26**(digits-1) if digits == 1: remainder -= 1 base26 += digit_value((x-remainder)/(26**(digits-1))) x = remainder digits -= 1 if negative: return '-'+base26 else: return base26