MS Word 文档中书签的超链接
是否可以从 WPF 文本块链接到 Word 文档中的书签?
到目前为止,我已经:
<TextBlock TextWrapping="Wrap" FontFamily="Courier New">
<Hyperlink NavigateUri="..\\..\\..\\MyDoc.doc"> My Word Document </Hyperlink>
</TextBlock>
我假设相对路径来自 exe 位置。我根本无法打开该文档。
Is it possible to link to a bookmark within a word document from a WPF text block?
So far I have:
<TextBlock TextWrapping="Wrap" FontFamily="Courier New">
<Hyperlink NavigateUri="..\\..\\..\\MyDoc.doc"> My Word Document </Hyperlink>
</TextBlock>
I am assuming the relative path is from the exe location. I can't get the document to open at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
作为我之前答案的补充,有一种编程方式可以打开本地 Word 文件、搜索书签并将光标放置在那里。我改编自这个优秀的答案。如果您有这种设计:
请使用以下代码:
As an addition to my previous answer, there is a programmatic way of opening a local Word file, searching for a bookmark and placing the cursor there. I adapted it from this excellent answer. If you have this design:
use this code:
在 WPF 应用程序中而不是在网页上使用超链接需要您自己处理 RequestNavigate 事件。
此处有一个很好的示例。
Using Hyperlink in a WPF application rather than on a web page requires you to handle the RequestNavigate event yourself.
There is a nice example here.
根据官方文档,它应该非常简单:
然而,有一个共识很多 非官方页面表明这只适用
.doc
文件(没有 Office 2007.docx
文件),不幸的是,尝试将其与
.docx
文件一起使用将产生错误。在 Office 2007 及更高版本上将其与.doc
文件一起使用将打开文档,但在第一页上。您可以使用 AutoOpen 宏来解决 Office 2007 及更高版本的限制,请参阅此处了解如何将宏参数传递给 Word。这将需要更改该系统使用的所有文档(并提出有关宏使用的其他问题)。
According to the official documentation, it should be surprisingly simple:
However, there is a consensus on a lot of inofficial pages that this only works
.doc
files (no Office 2007.docx
files), and unfortunatelyTrying to use this with
.docx
files will yield an error. Using this with.doc
files on Office 2007 and above will open the document, but on the first page.You may be able to work around the limitations of Office 2007 and above by using AutoOpen macros, see here for how to pass a Macro argument to Word. That would require changing all the documents to be used with that system (and raise additional questions about the use of macros).