打开 xlsx 文件时 openpyxl 库 StopIteration 错误

openpyxl library StopIteration error when opening xlsx file

我正在尝试打开一个 1.5mb 的 excel 文件,它有 25 sheets,每个 sheet 不超过 1000 行。该文件没有什么特别之处。它也不是只读的。 我需要对该文件执行一些自动化任务,但是当我尝试将其导入我的 Jupyther 环境时,出现以下错误:

---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-20-4584f4eff7cc> in <module>()
----> 1 eppm = oxl.load_workbook('DCB EPPM Demand Extract 2.xlsx')

~/anaconda3/envs/python3/lib/python3.6/site- 
packages/openpyxl/reader/excel.py in load_workbook(filename, read_only, 
keep_vba, data_only, guess_types, keep_links)
222 
223     apply_stylesheet(archive, wb) # bind styles to workbook
--> 224     pivot_caches = parser.pivot_caches
225 
226     # get worksheets

~/anaconda3/envs/python3/lib/python3.6/site- 
packages/openpyxl/packaging/workbook.py in pivot_caches(self)
123         d = {}
124         for c in self.caches:
--> 125             cache = get_rel(self.archive, self.rels, id=c.id, 
cls=CacheDefinition)
126             records = get_rel(self.archive, cache.deps, cache.id, 
RecordList)
127             cache.records = records

~/anaconda3/envs/python3/lib/python3.6/site- 
packages/openpyxl/packaging/relationship.py in get_rel(archive, deps, id, 
cls)
151         rel = deps[id]
152     else:
--> 153         rel = next(deps.find(cls.rel_type))
154 
155     path = rel.target

StopIteration: 

我无法共享文件,因为它包含公司信息,而且我无法创建虚拟数据来重新创建文件,因为 Python 错误似乎没有指出错误发生的位置。 我在 SO 上寻找过类似的错误,但 StopIteration 错误通常发生在人们使用循环时。 任何帮助将不胜感激!

问题不在于 openpyxl 或 python 环境。问题在于原始工作簿的保存方式。虽然它被保存为 .xlsx 文档但它不是 excel 工作簿,它是一个严格打开 XML 电子表格 .xlsx 所以乍一看,人们认为这个文件可以毫无问题地打开。 文件更改为 excel 工作簿 .xlsx 后文件加载没有问题。

我希望这 post 能帮助那些和我犯过同样错误的人!