using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System.IO.Packaging;
namespace OpenXMLConsole
{
class Program
{
static void Main(string[] args)
{
string path = @"E:\OpenXMLTable.docx";
using (WordprocessingDocument doc = WordprocessingDocument.Open(path,true))
{
Body body = doc.MainDocumentPart.Document.Body;
Paragraph para = body.AppendChild(new Paragraph());
//// Create an hyperlink
Hyperlink hyperlink = new Hyperlink();
//// The anchor attribute specifies that the target of the current hyperlink must be the text contained within the bookmark Description within the document
//// If no bookmark exists in the current document with the given bookmark name, then the default behavior shall be to navigate to the start of the document
hyperlink.Anchor = "Description";
hyperlink.DocLocation = "";
//// Append the hyperlink to the Paragraph
para.AppendChild(hyperlink);
//// Append the run to the hyperlink
Run run = hyperlink.AppendChild(new Run());
//// Append the text to the run
run.AppendChild(new Text("Click on description for more details"));
//// Save the document
doc.MainDocumentPart.Document.Save();
}
}
}