Convert spreadsheet number to column letter

前端 未结 13 1270
太阳男子
太阳男子 2020-11-30 05:47

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

13条回答
  •  余生分开走
    2020-11-30 06:17

    This simple Python function works for columns with 1 or 2 letters.

    def let(num):       
    
    alphabeth = string.uppercase
    na = len(alphabeth)
    
    if num <= len(alphabeth):
        letters = alphabeth[num-1]
    else:
        letters = alphabeth[ ((num-1) / na) - 1 ] +  alphabeth[((num-1) % na)]            
    
    return letters
    

提交回复
热议问题