Recommended best practices for working with temp Excel file to avoid corrupting original?

575 views
Skip to first unread message

Xtian Simon

unread,
Aug 31, 2018, 10:05:43 AM8/31/18
to openpyxl-users
My CLI script opens, writes to a sheet and saves an existing Excel document six times (add one sheet and update five sheets) before it's complete.
While my script was running, I realized I had an error in my code. I canceled using CTRL-C. After canceling, the existing Excel file exhibited this error on the next run of the CLI script:
   
    `("There is no item named '[Content_Types].xml' in the archive")`

None of this error message makes any sense in terms of my script or the file.
I realized canceling my script must have corrupted the Excel file.

To address this I think I should workup some sort of temp file process--such as:

What is the recommended best practice?
- make a temp file, open the original, work on the original, if error, restore to temp.
- make a temp file, work on the temp file, overwrite temp if no errors.
- or something else?

Reply all
Reply to author
Forward
0 new messages