Có cách nào khác để chuyển đổi các cột kiểu excel thành số (bắt đầu bằng 1) không?Chuyển đổi chữ cái excel hoặc bảng tính thành số của nó theo kiểu Pythonic
Làm việc mã lên đến hai chữ:
def column_to_number(c):
"""Return number corresponding to excel-style column."""
number=-25
for l in c:
if not l in string.ascii_letters:
return False
number+=ord(l.upper())-64+25
return number
Mã chạy:
>>> column_to_number('2')
False
>>> column_to_number('A')
1
>>> column_to_number('AB')
28
Ba chữ không làm việc.
>>> column_to_number('ABA')
54
>>> column_to_number('AAB')
54
tham khảo: question answered in C#
Và làm thế nào để bạn quay trở lại theo cách khác? –