如何通过索引获取 OpenPyXL 列字母

如果你想使用索引而不是字母访问 OpenPyXL 列,使用

openpyxl_get_column_letter.py
import openpyxl.utils.cell

openpyxl.utils.cell.get_column_letter(idx)

注意 idx 是从 1 开始的:索引 0 不是有效参数,索引 1 产生列名 A

例如:

openpyxl_example_usage.py
openpyxl.utils.cell.get_column_letter(3) # returns "C"

Check out similar posts by category: OpenPyXL, Python