Creating Hyperlink to a Bookmark (OpenXML/Word)
Wow, I seem to be having an incredibly hard time finding examples of inserting a Hyperlink to a bookmark.
If I create a simple Word document with a link to a bookmark, the link looks something like this.
<w:p w:rsidR="00B61E6F" w:rsidRDefault="00E56782"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:r>
<w:fldChar w:fldCharType="begin" />
</w:r>
<w:r>
<w:instrText xml:space="preserve"> HYPERLINK \l "Text" </w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType="separate" />
</w:r>
<w:r w:rsidRPr="00AC2FAA" w:rsidR="00AC2FAA">
<w:rPr>
<w:rStyle w:val="Hyperlin开发者_JAVA百科k" />
</w:rPr>
<w:t>Link</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink" />
</w:rPr>
<w:fldChar w:fldCharType="end" />
</w:r>
</w:p>
But what the heck is the instrText (FieldCode) value HYPERLINK \l "Text"
? Is it described somewhere?
I tried implementing the above pattern as is. The result is it works but, in some cases, the text does not appear as a hyperlink.
The element instrText is documented in Part 1, section 17.16.23 of the Open XML standard, and the specific HYPERLINK codes are documented in 17.16.5.25. You can get a free copy of this standard as "ECMA-376 2nd edition" at the Ecma 376 web page.
That doesn't exactly answer why your code doesn't work in some circumstances, though - are you perhaps pointing to a non-existent bookmark?
精彩评论