C# method to add Word text and picture hyperlinks
本文给大家介绍如何用C#编程语言对Word文档中的文本和图片进行超链接设置。感兴趣的朋友一起看看吧
超链接简单来讲就是内容链接,通过设置超链接可以实现对象与网页、站点之间的连接。链接目标可以是网页、图片、邮件地址、文件夹或者是应用程序。设置链接的对象可以是文本或者图片。
在以下内容中,我将介绍如何用C#编程语言对Word文档中的文本和图片进行超链接设置。执行该操作需要使用免费版组件Spire.Doc for. NET,可在这里下载安装(https://www.e-iceblue.cn/Downloads/Free-Spire-Doc-NET.html)
1.添加文本超链接
步骤一:创建一个Document实例并添加Section
Document doc = new Document(); Section section = doc.AddSection();
步骤二:添加指向网址的超链接
Paragraph para1 = section.AddParagraph(); para1.AppendHyperlink("www.google.com","www.google.com",HyperlinkType.WebLink);
步骤三:添加指向邮件地址的超链接
Paragraph para2 = section.AddParagraph(); para2.AppendHyperlink("mailto:support@e-iceblue.com", "support@e-iceblue.com", HyperlinkType.EMailLink);
步骤四:添加指向外部文件的超链接
Paragraph para3 = section.AddParagraph(); string filePath = @"C:\Users\Administrator\Desktop\2017NobelPrize.docx"; para3.AppendHyperlink(filePath, "点击打开文档", HyperlinkType.FileLink);
步骤五:设置段落之间的间距
para1.Format.AfterSpacing = 15f; para2.Format.AfterSpacing = 15f;
步骤六:保存文档
doc.SaveToFile("文本超链接.docx", FileFormat.Docx2013);
完成操作步骤后,运行该项目生成文件,如下图所示:
2、添加图片超链接
步骤一:创建一个Document实例并添加Section
Document doc = new Document(); Section section = doc.AddSection();
步骤二:添加段落
Paragraph para = section.AddParagraph();
步骤三:添加图片到段落并添加网站超链接
Image image = Image.FromFile(@"C:\Users\Administrator\Desktop\images\Google.jpg"); Spire.Doc.Fields.DocPicture picture = para.AppendPicture(image); para.AppendHyperlink("www.google.com", picture, HyperlinkType.WebLink);
步骤四:保存文档
doc.SaveToFile("图片超链接.docx", FileFormat.Docx2013);
完成操作步骤,运行程序得到如下文件:
总结
The above is the detailed content of C# method to add Word text and picture hyperlinks. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When editing content in a word document, lines may automatically wrap. If no adjustment is made at this time, it will have a great impact on our editing and make people very headache. What is going on? In fact, it is a problem with the ruler. Below, I will introduce the solution to how to cancel automatic word wrapping in word. I hope it can help everyone! After opening a Word document and entering text, when you try to copy and paste, the text may jump to a new line. In this case, you need to adjust the settings to solve this problem. 2. To solve this problem, we must first know the cause of this problem. At this time we click View under the toolbar. 3. Then click the "Ruler" option below. 4. At this time we will find that a ruler appears above the document with several conical markers on it.

When we use Word, in order to edit the content more beautifully, we often use rulers. You should know that the rulers in Word include horizontal rulers and vertical rulers, which are used to display and adjust the document's page margins, paragraph indents, tabs, etc. So, how do you display the ruler in Word? Next, I will teach you how to set the ruler display. Students in need should quickly collect it! The steps are as follows: 1. First, we need to bring up the word ruler. The default word document does not display the word ruler. We only need to click the [View] button in word. 2. Then, we find the option of [Ruler] and check it. In this way, we can adjust the word ruler! Yes or no

Word documents are widely used due to their powerful functions. Not only can various formats be inserted into Word, such as pictures and tables, etc., but now for the integrity and authenticity of the files, many files require a manual signature at the end of the document. It sounds like this How to solve complex problems? Today I will teach you how to add a handwritten signature to a word document. Use a scanner, camera or mobile phone to scan or photograph the handwritten signature, and then use PS or other image editing software to perform necessary cropping on the image. 2. Select "Insert - Picture - From File" in the Word document where you want to insert the handwritten signature, and select the cropped handwritten signature. 3. Double-click the handwritten signature picture (or right-click the picture and select "Set Picture Format"), and the "Set Picture Format" pops up.

Among office software, Word is one of our most commonly used software. The text documents we produce are generally operated with Word. Some documents need to be submitted in paper version as required. Before printing, the layout must be set before it can be presented. produce better results. So the question is, how do you set page margins in Word? We have specific course explanations to help you solve your doubts. 1. Open or create a new word document and click the "Page Layout" menu on the menu bar. 2. Click the "Margins" button of the "Page Setup" option. 3. Select a commonly used page margin in the list. 4. If there are no suitable margins in the list, click "Custom Margins". 5. The "Page Setup" dialog box pops up, enter the "Margins" option respectively.

Word is a software that we often use in our office. It has many functions that can facilitate our operations. For example, for a large article, we can use the search function inside to find out that a word in the full text is wrong, so we can directly replace it. Make changes one by one; when submitting the document to your superiors, you can beautify the document to make it look better, etc. Below, the editor will share with you the steps on how to draw a dotted line in Word. Let's learn together! 1. First, we open the word document on the computer, as shown in the figure below: 2. Then, enter a string of text in the document, as shown in the red circle in the figure below: 3. Next, press and hold [ctrl+A] Select all the text, as shown in the red circle in the figure below: 4. Click [Start] on the top of the menu bar

We often use word for office work, but do you know where the shading settings are in word? Today I will share with you the specific operation steps. Come and take a look, friends! 1. First, open the word document, select a paragraph of text paragraph information that needs to be added with shading, then click the [Start] button on the toolbar, find the paragraph area, and click the drop-down button on the right (as shown in the red circle in the figure below) ). 2. After clicking the drop-down box button, in the pop-up menu options, click the [Border and Shading] option (as shown in the red circle in the figure below). 3. In the pop-up [Border and Shading] dialog box, click the [Shading] option (as shown in the red circle in the figure below). 4. In the filled column, select a color

Sometimes, we often encounter counting problems in Word tables. Generally, when encountering such problems, most students will copy the Word table to Excel for calculation; some students will silently pick up the calculator. Calculate. Is there a quick way to calculate it? Of course there is, in fact the sum can also be calculated in Word. So, do you know how to do it? Today, let’s take a look together! Without further ado, friends in need should quickly collect it! Step details: 1. First, we open the Word software on the computer and open the document that needs to be processed. (As shown in the picture) 2. Next, we position the cursor on the cell where the summed value is located (as shown in the picture); then, we click [Menu Bar

When you make a graduation thesis or resume cover, you will write your gender, age, class and other information on the cover, and draw a line behind it and write your own information. Then it involves the issue of underlining the name. That is what everyone is asking about how to underline in word. Below I will share with you the specific steps. Come and learn! First, open the document on your computer, click the [Start] button on the top toolbar of Word, and then click the underlined icon button under the letter [U], as shown in the red circle in the figure below. 2. Then, place the cursor where you want to underline, and then press the space bar on the keyboard. At this time, the underline will appear. The length of the underline can be controlled according to the number of spaces, as shown in the red circle in the figure below
