Convert spreadsheet number to column letter

前端 未结 13 1233
太阳男子
太阳男子 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:21

    Just for people still interest in this. The chosen answer by @Marius gives wrong outputs in some cases, as commented by @jspurim. Here is the my answer.

    import string
    def convertToTitle(num):
        title = ''
        alist = string.uppercase
        while num:
            mod = (num-1) % 26
            num = int((num - mod) / 26)  
            title += alist[mod]
        return title[::-1]
    

提交回复
热议问题