Skip to content Skip to sidebar Skip to footer

Xlsx And Xlsm Files Return Badzipfile: File Is Not A Zip File

I'm trying to open both an xlsx file and an xlsm file both give me the same error badzipfile: file is not a zip file here is what I'm typing: import openpyxl wb=openpyxl.load_wor

Solution 1:

It's because you created empty .xlsx with no metadata which is an empty file with no cells formatting. use exel or equivalent spreadsheet software to save empty file in that directory, which will create an xlsx file with cell formating, after saving try to load file using openpyxl

Solution 2:

If you call openpyxl.load_workbook with file-like object, be sure to open it in binary mode.

Solution 3:

I did something really stupid and got the same error. Basically, today was my first time trying this and I got it to work with the 'Automate' example and then tried my Excel. Didn't work! Took me a while to realize the error was due to having workbook password protected. The error doesn't match that at all, but when I removed the protection from the workbook, it worked! What can I say but 'duh' and 'yeah!'?

Solution 4:

I'm late to the party, but I received the same error, but for different reasons.

On my mac, when I cut and pasted the .xlsx file into the directory I desired, it didn't actually place the file itself, it placed a symbolic link. That, for some reason, would raise the same error. I remedied this by opening the file, and using "save as".

Solution 5:

The XLSX or XLS or XLSM files you are trying to open are excel recovery files start with "~". you can check by:

for file inpath.glob('*.xlsx'):print(file)

you can skip those files by checking,get filename from full path:

filename=str(filename).split("\\")[-1:][0]

checking if the filename starts with "~" as all recovery files will start with "~"

if filename[0]!="~"

Post a Comment for "Xlsx And Xlsm Files Return Badzipfile: File Is Not A Zip File"