Relationships in case of cells with hyperlinks are duplicated on every workbook.save()
Try running the following code in OpenPyXL 3.0.3:
from openpyxl import load_workbook
wb = load_workbook("test_before.xlsx")
for a in range(100):
wb.save("test_after.xlsx")
This results in sheet1.xml
(I access it by opening test_after.xlsx
using 7z or similar and navigating to xl/worksheets
folder) containing
<hyperlinks>
<hyperlink ref="A1" r:id="rId100" />
<hyperlink ref="A1" r:id="rId100" />
<hyperlink ref="A1" r:id="rId100" />
<hyperlink ref="A1" r:id="rId100" />
<hyperlink ref="A1" r:id="rId100" />
<hyperlink ref="A1" r:id="rId100" />
<hyperlink ref="A1" r:id="rId100" />
<hyperlink ref="A1" r:id="rId100" />
<hyperlink ref="A1" r:id="rId100" />
<hyperlink ref="A1" r:id="rId100" />
...
and the _rels
directory has sheet1.xml.rels
with contents
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
<Relationship Id="rId2" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
<Relationship Id="rId3" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
<Relationship Id="rId4" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
<Relationship Id="rId5" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
<Relationship Id="rId6" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
<Relationship Id="rId7" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
<Relationship Id="rId8" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
<Relationship Id="rId9" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
<Relationship Id="rId10" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" />
...
Clearly this is not the intended behavior, because for larger sheets with lots of links this gets out of control very fast. So, in my opinion, a pretty serious issue.