简体   繁体   English

Excel 列,openpyxl

[英]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:我制作了一个使用openpyxl的程序,我正在尝试寻找一个将列号转换为相应字母的程序,例如:

>>> _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.我尝试使用int(n + 10, base = 36)但对于多位列,它不起作用。

Openpyxl already has a function, called get_column_letter , which converts a column number to a letter. Openpyxl 已经有一个名为get_column_letter的 function ,它将列号转换为字母。 Here is the code:这是代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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