其他分享
首页 > 其他分享> > 写入Excel时将数字列号转换为字符标签列

写入Excel时将数字列号转换为字符标签列

作者:互联网

写入Excel时将数字列号转换为字符标签列

直接上代码

def convertToTitle(n):
    """
    :type n: int
    :rtype: str
    """
    rStr = ""
    while n != 0:
        res = n % 26
        if res == 0:
            res = 26
            n -= 26
        rStr = chr(ord('A')+res-1) + rStr
        n = n//26
    return rStr

标签:26,rStr,Excel,写入,列号,res
来源: https://blog.csdn.net/FPSol/article/details/114403614