‘ReadOnlyWorksheet’ 对象没有 ‘defined_names’ 属性。

huangapple go评论49阅读模式
英文:

'ReadOnlyWorksheet' object has no attribute 'defined_names'

问题

每当我尝试使用以下代码读取Excel时:

part = pd.read_excel(path, sheet_name=mto_sheet)

我会得到这个异常:

<class 'Exception'> 'ReadOnlyWorksheet'对象没有属性'defined_names'

这是在我使用Visual Studio Code和Python 3.11时出现的。然而,当我使用Anaconda时,我没有这个问题。有什么原因吗?

英文:

Whenever I try to read Excel using

part=pd.read_excel(path,sheet_name = mto_sheet)

I get this exception:

> <class 'Exception'> 'ReadOnlyWorksheet' object has no attribute 'defined_names'

This is if I use Visual Studio Code and Python 3.11. However, I don't have this problem when using Anaconda. Any reason for that?

答案1

得分: 47

这个错误似乎是由最新版本的 openpyxl 引起的。
你可以通过降级到较低版本来修复它

pip install --force-reinstall -v "openpyxl==3.1.0"
英文:

The error seems to be caused by the latest version of openpyxl.
You can fix it by downgrading to a lower version

pip install --force-reinstall -v &quot;openpyxl==3.1.0&quot;

答案2

得分: 5

似乎问题已在 openpyxl 3.1.2 中修复 😃

pip install --upgrade openpyxl
英文:

Seems like the issue is fixed in openpyxl 3.1.2 😃

pip install --upgrade openpyxl

答案3

得分: 2

可能的解决方法:创建一个新的Excel文件,使用默认工作表名称("Sheet1"等),然后将数据复制粘贴到这里。

(已在Python 3.10.9 + openpyxl==3.1.1上测试)

英文:

Possible workaround: create new excel file, with default worksheet name ("Sheet1" etc.) and copy and paste data here.

(tested on Python 3.10.9 + openpyxl==3.1.1)

huangapple
  • 本文由 发表于 2023年2月16日 19:02:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471318.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定