I have been trying to re-link a .docx file that contains many hyperlinks embedded inside text sections since we decided to change document storage services. So the links on the docx are old and need to be swapped out with the new updated links. I am able to access all the old links using the python-docx library and have saved them in a csv, but I can't figure out a way to edit/swap out the old hyperlinks with new ones.
I have tried doing
hyperlink.address = "www.google"
expecting to be able to change the embedded address. But that threw the error AttributeError: property 'address' of 'Hyperlink' object has no setter
Even when I try replacing the entire link object, nothing seems to happen even after I save the document and the document would be the same as the old document.
counter = 0
for table in document.tables:
for row in table.rows:
for cell in row.cells:
for paragraph in cell.paragraphs:
hyperlinks = paragraph.hyperlinks
for link in hyperlinks:
link = "www.google"
document.save('TABLETEST2.docx')
I would love help on how to approach this problem either using python-docx or some other library/tool, Thank you!