ImportError:无法导入名称get_column_letter

cha*_*rsi 23 python module importerror python-2.7 openpyxl

我可以在我的代码中使用openpyxl作为导入.但是,当我尝试执行以下操作时:

from openpyxl.cell import get_column_letter 
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

ImportError: cannot import name get_column_letter
Run Code Online (Sandbox Code Playgroud)

我正在使用python 2.7.我用它安装了它easy_install.尝试搜索此问题但找不到与之相关的任何内容.

Abb*_*bas 43

该函数get_column_letter已在Openpyxl 2.4版本中重新定位openpyxl.cellopenpyxl.utils.

目前的进口是: from openpyxl.utils import get_column_letter

如果您不想知道最终用户具有哪个版本,可以使用以下代码:

try: 
    from openpyxl.cell import get_column_letter
except ImportError:
    from openpyxl.utils import get_column_letter
Run Code Online (Sandbox Code Playgroud)