Excel file becomes corrupted when saved

Issue #1296 resolved
Per created an issue

Hello,

I have an Excel file (“openpyxl_corrupt_file.xlsx”) which becomes corrupted when saved (“openpyxl_corrupt_file_saved.xlsx”) as seen in the attached screen dump (“Capture.JPG”). The screen dump is generated when the saved filed is opened and repaired in Excel.

The saved file is generated by (See the attached script “openpyxl_corrupt_file.py” ):

import openpyxl
wb = openpyxl.load_workbook(filename=r'C:\temp\openpyxl_corrupt_file.xlsx', data_only=True)
wb.save(filename=r'C:\temp\openpyxl_corrupt_file_saved.xlsx')

I hope you are able to figure out how to modify the openpyxl code to ensure it writes a correct Excel file.

Openpyxl version = 2.6.2

PS: If the “custom view” is removed from the excel file then the file seems to be correctly saved.

PPS: I’m a newbie and this is my first issue report, so if you have any advise/suggestions to improve my description or anything else don’t hesitate to let me know 😊

Thanks in advance and thanks for a great module

Comments (3)

  1. CharlieC

    Thanks for the file. I suspect the problem is related to the rowBreaks which appear duplicate in the openpyxl file.

    This is due to customSheetView also containing such definitions which isn’t supported but trips the parser up.

  2. Log in to comment