C # Implementation method for adding word text to a picture hyperlink

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.