>>> import openpyxl
>>> from openpyxl.utils import get_column_letter,column_index_from_string
>>> get_column_letter(1)
'A'
>>> get_column_letter(3)
'C'
>>> get_column_letter(55)
'BC'
>>> column_index_from_string('BC')
55
>>> column_index_from_string('Bc')
55
>>> column_index_from_string('C')
3
另外今天还发现了一个与《python编程快速上手——让繁琐的工作自动化》一书上不一样的地方。书上用的是:
from openpyxl.cell import get_column_letter,column_index_from_string
这可能是由于版本的原因,书上用的openpyxl的版本是2.1.4,而我用的是3.0.2,官网最新版本是3.0.5
另附上官网的地址:
https://openpyxl.readthedocs.io/en/stable/