Translate a column index into an Excel Column Name

前端 未结 15 2347
花落未央
花落未央 2020-11-27 20:41

Given a columns\' index, how can you get an Excel column name?

The problem is trickier than it sounds because it\'s not just base-26. The columns

15条回答
  •  生来不讨喜
    2020-11-27 21:12

    in python, with recursion. translated from Joey's answer. so far, it's tested to work up to GetExcelByColumn(35) = 'AI'

    def GetExcelColumn(index):
    
        quotient = int(index / 26)
    
        if quotient > 0:
            return GetExcelColumn(quotient) + str(chr((index % 26) + 64))
    
        else:
            return str(chr(index + 64))
    

提交回复
热议问题