2016-11-10 8 views
0

OpenXMLを使用して、各段落の単語文書からハイパーリンクのアドレスを取得しようとしています。OpenXMLで単語のハイパーリンクを見つける方法

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

答えて

0

私はそれが返信用

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); 
} 
+0

おかげであるべきと考えています。エラー: 'シーケンスに一致する要素がありません' ExternalRelationship hyperlinkRelationship = doc ..... –

+0

openxmlとC#を使用して、ハイパーリンクからハイパーリンクからリンクURLを取得する方法を探しています。それは外部リンク関係ではなく、HyperlinkRelationshipsです。私はそれを変更するまでシーケンスエラーも出てきた。 HIH – Lysis

関連する問題