Fetch all links from all shapes in a document efficiently

Fetch all links from all shapes in a document efficiently



 Feb 25 2024

I would like to have the possibility to efficiently fetch all links from all shapes in a document.

The links are stored in /word/_rels/*.rels package parts, e.g. /word/_rels/document.xml.rels for the main content in the form of

<Relationship Id="*" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="<the link URL to be fetched>" TargetMode="External"/>

The only way that I know how I can do this is by fetching the OOXML of the whole document via context.document.body.getOoxml() and then scanning it for the appropriate package parts and Relationship entries which is quite slow and inefficient especially on large documents.

It would also be nice to directly access the contents of the document ZIP parts, e.g. /word/_rels/document.xml.rels.

Accessing all hyperlink ranges of a document, e.g. via context.document.body.getRange("Content").getHyperlinkRanges() does not yield the links of shapes in a document.

Related issue: https://github.com/OfficeDev/office-js/issues/4160

Thank you and regards,