I have made a python script which is meant to read an excel spreadsheet and return the value of cell A39. I'm using the openpyxl library.
Here is the part of the code that is giving an error:
cFile = openpyxl.load_workbook('contacts.xlsx', read_only= True)
sheet = cFile.get_sheet_by_name('cSheet')
print sheet['A39'].value
Instead of printing the value of cell A39, which in the spreadsheet is "38", I get the following error:
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
The spreadsheet 'contacts.xlsx' is not a zipped file. It is in the same folder as the python script. I made it with Excel 2011. Does anyone know why I'm getting this error or how I can fix it?
Thanks!
When I had the same similar error, I also couldn't understand the issue. Also working with openpyxl library. My root problem was that some file was opened and save at the same time while using some kind of Multithreading. For a solution, I changed the name of the file according to every thread. you could also use some locks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With