2016-07-12 3 views
1

こんにちは現在、私はopen xmlを使って画像を自分のワード文書に追加しました。画像にハイパーリンクを追加する必要があります。だから、誰かが文書内の画像をクリックすると、特定のWeb URLに移動します。どのように私はこれを達成することができます。誰か助けてください。画像コードの追加は以下に追加されています。Open xml文書の画像付きハイパーリンクを追加

var run1 = new Run(); 
         var picture1 = new Picture(); 
         var shape1 = new Shape() { Id = "_x0000_i1025" + x}; 

        string rId = "rId" + x ; 
        var imageData1 = new ImageData() { RelationshipId = rId }; 
        shape1.Append(imageData1); 
        picture1.Append(shape1); 
        run1.Append(picture1); 

        mainPart.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", 
        new System.Uri(matchString, System.UriKind.RelativeOrAbsolute), rId); 

        DocumentFormat.OpenXml.Wordprocessing.TableRow tr1 = new DocumentFormat.OpenXml.Wordprocessing.TableRow(); 
        DocumentFormat.OpenXml.Wordprocessing.TableCell Name1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new Paragraph(new Run(new Text(item.FirstName)))); 
        DocumentFormat.OpenXml.Wordprocessing.TableCell Message1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new Paragraph(run1)); 
        DocumentFormat.OpenXml.Wordprocessing.TableCell Time1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new Paragraph(new Run(new Text(item.CreatedDate)))); 
        tr1.Append(Name1, Message1, Time1); 
        table.AppendChild(tr1); 
        x++; 
+0

の可能性のある重複した[オープンXMLを使用してDOCX Wordにハイパーリンクを追加する方法?](http://stackoverflow.com/questions/16085754/how-to-add-hyperlinks-into-word-docx-using -open-xml) – lokusking

答えて

1

回答が見つかりました。これが誰かを助けてくれるかも。

var run1 = new Run(); 
          var picture1 = new Picture(); 
          var shape1 = new Shape() { Id = "_x0000_i1025" + x}; 

          string hyperid="hprid_"+x; 
          var hlink = new Hyperlink() { Id=hyperid, DocLocation=matchString}; ; 
          hlink.Append(picture1); 

          string rId = "rId" + x ; 
          var imageData1 = new ImageData() { RelationshipId = rId }; 
          shape1.Append(imageData1); 
          picture1.Append(shape1); 
          run1.Append(hlink); 
          mainPart.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", 
          new System.Uri(matchString, System.UriKind.RelativeOrAbsolute), rId); 

          mainPart.AddHyperlinkRelationship(new Uri(matchString), true, hyperid); 


          DocumentFormat.OpenXml.Wordprocessing.TableRow tr1 = new DocumentFormat.OpenXml.Wordprocessing.TableRow(); 
          DocumentFormat.OpenXml.Wordprocessing.TableCell Name1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new Paragraph(new Run(new Text(item.FirstName)))); 
          DocumentFormat.OpenXml.Wordprocessing.TableCell Message1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new Paragraph(run1)); 
          DocumentFormat.OpenXml.Wordprocessing.TableCell Time1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new Paragraph(new Run(new Text(item.CreatedDate)))); 
          tr1.Append(Name1, Message1, Time1); 
          table.AppendChild(tr1); 
関連する問題