简体   繁体   中英

Excel columns, openpyxl

I have made a program that uses openpyxl and I am trying to look for a program that translate column numbers to the respective letters eg:

>>> _get_exl_base26(1)
A
>>> _get_exl_base26(676)
ZZ
>>> etc.

Is this possible?

I tried using int(n + 10, base = 36) but for the multi-digited columns, it didn't work.

Openpyxl already has a function, called get_column_letter , which converts a column number to a letter. Here is the code:

from openpyxl.utils import get_column_letter
# Change n to the column number
n = 1
print(get_column_letter(n))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM