c# - 如何使用 Open XML 将超链接添加到 Word docx 中?

标签 c# sharepoint openxml

我在向我的 word 文档添加超链接时遇到问题。我不知道该怎么做。我想使用打开的 xml 从我的 C# 代码在 word 文档中建立链接。是否有其他解决方案仅使用 href 或类似的东西?网上有一个来自 Open XML 的 HyperLink 类,但是如何使用它呢?

最佳答案

试试这个

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();

}

关于c# - 如何使用 Open XML 将超链接添加到 Word docx 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16085754/

相关文章:

SharePoint:备份单页

c# - 后备策略日志授权事件

c# - 如何使用 UIElement 依赖属性实现 WPF 用户控件?

c# - C# 弱引用实际上是软引用吗?

sharepoint - 缺少 Visual Studio 2012 中用于 sharepoint 2013 开发的先决条件

sharepoint - Microsoft Dynamics CRM 集成 SharePoint

c# - 替换 OpenXML 中内容控件的文本

powershell - 使用 powershell 在 openxml 中创建一个新行

c# - 使用 OpenXml Sdk 2.0 在 Word 中水平文本对齐

c# - 我想通过将输入数组的所有项目相乘来计算,但除了第 i 个项目