将电子表格编号转换为列字母 [英] Convert spreadsheet number to column letter

查看:41
本文介绍了将电子表格编号转换为列字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找与此问答相反的内容:以 Pythonic 方式将 excel 或电子表格列字母转换为其数字.

I'm looking for the opposite to this Q&A: Convert an excel or spreadsheet column letter to its number in Pythonic fashion.

或者这个但是在 python 如何将列号(例如127)转换为excel列(例如AA)

or this one but in python How to convert a column number (eg. 127) into an excel column (eg. AA)

推荐答案

def colnum_string(n):
    string = ""
    while n > 0:
        n, remainder = divmod(n - 1, 26)
        string = chr(65 + remainder) + string
    return string

print(colnum_string(28))
#output:AB

这篇关于将电子表格编号转换为列字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆