2

I have a simple Excel xlsx file with one sheet and one external link which becomes corrupted if I open it and save it with openpyxl.

This is a question similar to others (here and here and elsewhere). However, my example does not contain complicated excel features like charts / images / macros. And my example is not solved by different versions of openpyxl. I have tested these versions of openpyxl:

  • 3.0.3
  • 2.4
  • 3.1.1
  • 3.1.2

I have a simple Excel file with one sheet. It has one formula which is a link to another workbook. The formula is:

='C:\Temp\temp\[Book2.xlsx]Sheet1'!$A$3

Now I run the simple program:

def main():
    f1="C:/Temp/temp/Book1.xlsx"
    print(openpyxl.__version__)
    wb=openpyxl.load_workbook(filename=f1)
    wb.save(f1)
    wb.close()

After I run this the file becomes corrupted:

enter image description here

If I allow Excel to attempt to recover the file, the external link appears as: =[RecoveredExternalLink1]Sheet1!$A$3

I can update this link to the original file and no other corruption appears to have occurred.

This problem seems to have happened recently. Similar code I have been using for over a year has started to produce this issue in the last couple of months. My version of Excel (64 bit) is:

enter image description here

Tim
  • 291
  • 2
  • 17

0 Answers0