How to add hyperlinks into Word docx using open XML?

前端 未结 1 1577
囚心锁ツ
囚心锁ツ 2021-01-12 08:09

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 th

1条回答
  •  隐瞒了意图╮
    2021-01-12 08:32

    Try this

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

    0 讨论(0)
提交回复
热议问题