如何使用开放XML将超链接添加到Word docx? [英] How to add hyperlinks into Word docx using open XML?
本文介绍了如何使用开放XML将超链接添加到Word docx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将超链接添加到我的Word文档时遇到麻烦.我不知道该怎么做.我想使用开放xml在我的C#代码中的Word文档中建立链接.是仅使用href或sth的其他解决方案吗? Open XML在网上有一个HyperLink类,但是如何使用它呢?
I am having a trouble adding hyperlinks to my word document. I don't know how to do it. I would like to make a link in a word document from my C# code using open xml. Is ther a different solution using only href or sth similar? There is a HyperLink class on the net from Open XML but how to use it?
推荐答案
尝试一下
using (WordprocessingDocument doc = WordprocessingDocument.Open("", true))
{
doc.MainDocumentPart.Document.Body.AppendChild(
new Paragraph(
new Hyperlink(new Run(new Text("Click here")))
{
Anchor = "Description",
DocLocation = "location",
}
)
);
doc.MainDocumentPart.Document.Save();
}
这篇关于如何使用开放XML将超链接添加到Word docx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文