如何使用 open XML 在 Word docx 中添加超链接? [英] How to add hyperlinks into Word docx using open XML?

查看:31
本文介绍了如何使用 open XML 在 Word docx 中添加超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在向 Word 文档添加超链接时遇到问题.我不知道该怎么做.我想使用 open 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();

}

这篇关于如何使用 open XML 在 Word docx 中添加超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆