Page 1 of 1

Package explorer and Hyperlinks

PostPosted: Wed Nov 11, 2015 8:38 am
by finder
Hello. I'm new to docx4j. I'm looking for a solution as to how to search and replace hyperlinks in word docs. As a test, I created a simple document with only two words in it. one is a normal text and the other is a hyperlink that links to www.google.com.

I got this using the package explorer:
<w:document mc:Ignorable="w14 w15 wp14">
<w:body>
<w:p/>
<w:p/>
<w:p/>
<w:p>
<w:r>
<w:t>Test</w:t>
</w:r>
</w:p>
<w:p/>
<w:p/>
<w:p>
<w:bookmarkStart w:name="_GoBack" w:id="0"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:p/>
<w:p>
<w:hyperlink w:history="true" r:id="rId4">
<w:proofErr w:type="gramStart"/>
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>hello</w:t>
</w:r>
<w:proofErr w:type="gramEnd"/>
</w:hyperlink>
</w:p>
<w:sectPr>
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
<w:cols w:space="720"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
</w:document>

I could not find where the www.google.com is. I clicked on each xml tag links and could not find the link. I'm wondering if the links is really not displayed or i'm doing something wrong?

Thanks!

Re: Package explorer and Hyperlinks

PostPosted: Wed Nov 11, 2015 10:56 pm
by jason
It'll be "in" r:id="rId4" on the w:hyperlink element.

If you look at the relationships part, there'll be an rel of type external bearing that ID, pointing to Google.

To add a hyperlink, you have to add that external rel, and use the relId on the hyperlink element.

See https://github.com/plutext/docx4j/blob/ ... kTest.java