Get Excel-Style Column Names from Column Number

前端 未结 8 1580
慢半拍i
慢半拍i 2020-12-01 12:38

This is the code for providing the COLUMN name when the row and col ID is provided but when I give values like row = 1 and col = 104, it should return CZ<

8条回答
  •  爱一瞬间的悲伤
    2020-12-01 13:10

    use this code:

    def xlscol(colnum):
        a = []
        while colnum:
            colnum, remainder = divmod(colnum - 1, 26)
            a.append(remainder)
        a.reverse()
        return ''.join([chr(n + ord('A')) for n in a])
    

提交回复
热议问题