This article shows you how to use the C # programming language to set up hyperlinks to text and pictures in a Word document. Interested friends to see it together
Hyperlinks are simply links to content, which allows you to connect objects to Web pages and sites by setting up hyperlinks. A link destination can be a Web page, picture, email address, folder, or application. The object that sets the link can be text or a picture.
In the following, I'll show you how to make hyperlink settings for text and pictures in a Word document in the C # programming language. Doing this requires the use of the free version of the component Spire.doc for. NET, can download install here (https://www.e-iceblue.cn/Downloads/Free-Spire-Doc-NET.html)
1. Add a text hyperlink
Step one: Create a document instance and add section
Document doc = new document (); Section section = Doc. AddSection ();
Step two: Add a hyperlink to the URL
Paragraph para1 = section. Addparagraph ();p ara1. Appendhyperlink ("www.google.com", "www.google.com", Hyperlinktype.weblink);
Step three: Add a hyperlink to a mail address
Paragraph para2 = section. Addparagraph ();p ara2. Appendhyperlink ("mailto:support@e-iceblue.com", "support@e-iceblue.com", Hyperlinktype.emaillink);
Step four: Add a hyperlink to an external file
Paragraph para3 = section. Addparagraph (); string filePath = @ "C:\Users\Administrator\Desktop\2017NobelPrize.docx";p ara3. Appendhyperlink (FilePath, "Click to open Document", Hyperlinktype.filelink);
Step five: Set the spacing between paragraphs
Para1. format.afterspacing = 15f;para2. format.afterspacing = 15f;
Step Six: Save the document
Doc. SaveToFile ("text hyperlink. docx", fileformat.docx2013);
After you complete the operation steps, run the project build file as shown in:
2. Add Picture Hyperlink
Step one: Create a document instance and add section
Document doc = new document (); Section section = Doc. AddSection ();
Step Two: Add a paragraph
Paragraph para = section. Addparagraph ();
Step three: Add a picture to a paragraph and add a Web hyperlink
Image image = Image.FromFile (@ "C:\Users\Administrator\Desktop\images\Google.jpg"); Spire.Doc.Fields.DocPicture picture = para. Appendpicture (image);p Ara. Appendhyperlink ("www.google.com", picture, Hyperlinktype.weblink);
Step four: Save the document
Doc. SaveToFile ("Picture hyperlink. docx", fileformat.docx2013);
To complete the procedure, run the program to get the following files:
Summarize