【问题标题】:How to find word hyperlink with OpenXML如何使用 OpenXML 查找单词超链接
【发布时间】:2017-08-23 12:46:15
【问题描述】:

我正在尝试使用 OpenXML 从每个段落的 word 文档中获取超链接地址。

public static string GetAddressFromPara(Paragraph Paras)
{
    IEnumerable<Hyperlink> hplk = Paras.Descendants<Hyperlink>();
    if (hplk != null)
    {
        foreach (Hyperlink hp in hplk)
        {
            //string address = ???????;
        }
    }
}

【问题讨论】:

    标签: c# ms-word openxml


    【解决方案1】:

    我认为应该是

    foreach (Hyperlink hp in hplk)
    {
        hyperlinkText = new StringBuilder();
        foreach (Text text in hp.Descendants<Text>())
            hyperlinkText.Append(text.InnerText);
    
        hyperlinkRelationshipId = hp.Id.Value;
    
    
        ExternalRelationship hyperlinkRelationship = doc
            .MainDocumentPart
            .ExternalRelationships
            .Single(c => c.Id == hyperlinkRelationshipId);
    
        hyperlinkUri = new StringBuilder(hyperlinkRelationship.Uri.AbsoluteUri);
    }
    

    【讨论】:

    • 感谢您的回复。在 ExternalRelationship hyperlinkRelationship = doc ...
    • 遇到了这个答案,搜索如何使用 openxml 和 C# 从 word 中的超链接获取链接 URL。它是超链接关系而不是外部关系。在我更改它之前,我也收到了序列错误。嗨
    猜你喜欢
    • 2021-09-02
    • 2012-10-16
    • 1970-01-01
    • 2021-04-02
    • 2019-02-27
    • 2014-07-15
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    相关资源
    最近更新 更多