gpt4 book ai didi

python - 使用 openpyxl 时出现 "Bad magic number for file header"错误

转载 作者:行者123 更新时间:2023-12-04 11:42:21 26 4
gpt4 key购买 nike

我制作了一个 python 脚本,用于读取 Excel 电子表格并返回单元格 A39 的值。我正在使用 openpyxl 库。

这是给出错误的代码部分:

cFile = openpyxl.load_workbook('contacts.xlsx', read_only= True)
sheet = cFile.get_sheet_by_name('cSheet')

print sheet['A39'].value

我没有打印电子表格中为“38”的单元格 A39 的值,而是收到以下错误:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 971, in open
raise BadZipfile("Bad magic number for file header")
zipfile.BadZipfile: Bad magic number for file header

电子表格“contacts.xlsx”不是压缩文件。它与 python 脚本位于同一文件夹中。我是用 Excel 2011 完成的。有谁知道我为什么会收到此错误或如何修复它?

谢谢!

最佳答案

当我遇到同样类似的错误时,我也无法理解这个问题。
还使用 openpyxl 库。
我的根本问题是在使用某种多线程时同时打开并保存了一些文件。作为解决方案,我根据每个线程更改了文件的名称。你也可以使用一些锁。

关于python - 使用 openpyxl 时出现 "Bad magic number for file header"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45121132/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com