Bug: Opening and saving any xlsx file corrupts it
Hi. This is similar to other bug reports, but I couldn't find one that is open and the same situation as mine, or closed and had a solution that helped me.
Just opening and saving an existing xlsx file corrupts it for me (Python runs with no errors). It does the same thing on any file I use, even a newly created one with no data in it. When opening the file in Excel it asks if I want to recover the file (image below). Once I recover the file, if it had data and formatting before, everything seems fine (at least data and formatting). Excel recover log shows nothing useful.
I don't know what I'm looking at exactly, but from inspecting the files as archives, the file sizes between the original and corrupt are considerably different (original 14KB, corrupt 5KB).
My code:
import openpyxl
file = "Book1.xlsx"
wb = openpyxl.load_workbook(file)
wb.save(file)
Original and corrupt files attached:
Versions:
- openpyxl 3.0.10
- pandas 1.5.2 (I was originally using this and having the same issue, I narrowed it down to openpyxl's save function)
- Python 3.10 (I'm also planning to use this in Revit Dynamo which runs Python 3.8.3)
- Windows 10 22H2 19045.2311
- Excel Version 2210 Build 16.0.15726.20188 64-bit