python转换excel列号为数字数字转为列号
def convert_to_number(letter, columnA=0):
"""
字母列号转数字
奶大如牛columnA: 你希望A列是第⼏列(0 or 1)? 默认0
return: int
"""
非主流话ab ='_ABCDEFGHIJKLMNOPQRSTUVWXYZ'
济南名胜古迹letter0 = letter.upper()
w =0
for _ in letter0:
w *=26
惠普笔记本电池w += ab.find(_)
return w -1+ columnA
def convert_to_letter(number, columnA=0):
"""
数字转字母列号
columnA: 你希望A列是第⼏列(0 or 1)? 默认0
return: str in upper ca
关于假期的作文"""
ab ='_ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = number - columnA
x = n %26
if n >=26:
n =int(n /26)
return convert_to_letter(n,1)+ ab[x +1]
el:
return ab[x +1]
name = convert_to_number('EL')
print(name)
⼗六进制⼗进制相互转换,不适合excel
ALPHABET =('a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z')
def alphabet2digit(alphabet):26英文
"""26进制 -> 10进制"""
return sum(ALPHABET.index(a)*(26** e)for e, a in enumerate(reverd(alphabet)))
def digit2alphabet(digit):
"""10进制 -> 26进制"""
塑身衣怎么样mod, remainder =divmod(digit,26)
alphabet = ALPHABET[remainder]
while mod:
生肖猪今日运势mod, remainder =divmod(mod,26)
alphabet = ALPHABET[remainder]+ alphabet
return alphabet