溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

C# 如何添加文本和圖片超鏈接到Word

發(fā)布時間:2020-07-22 00:19:20 來源:網(wǎng)絡(luò) 閱讀:535 作者:Eiceblue 欄目:編程語言

超鏈接簡單來講就是內(nèi)容鏈接,通過設(shè)置超鏈接可以實現(xiàn)對象與網(wǎng)頁、站點之間的連接。鏈接目標可以是網(wǎng)頁、圖片、郵件地址、文件夾或者是應(yīng)用程序。設(shè)置鏈接的對象可以是文本或者圖片。

在以下內(nèi)容中,我將介紹如何用C#編程語言對Word文檔中的文本和圖片進行超鏈接設(shè)置。執(zhí)行該操作需要使用免費版組件Spire.Doc for. NET,可在這里下載安裝(https://www.e-iceblue.cn/Downloads/Free-Spire-Doc-NET.html


1.添加文本超鏈接

步驟一創(chuàng)建一個Document實例并添加section

Document doc = newDocument();
Section section =doc.AddSection();

步驟二:添加指向網(wǎng)址的超鏈接

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

步驟五:設(shè)置段落之間的間距

para1.Format.AfterSpacing = 15f;
para2.Format.AfterSpacing= 15f;

步驟六:保存文檔

doc.SaveToFile("文本超鏈接.docx", FileFormat.Docx2013);

C# 如何添加文本和圖片超鏈接到Word


2.添加圖片超鏈接

步驟一:創(chuàng)建一個Document實例并添加section

Document doc = newDocument();
Section section =doc.AddSection();

步驟二:添加段落

Paragraph para = section.AddParagraph();

步驟三:添加圖片到段落并插入網(wǎng)站鏈接

Image p_w_picpath = Image.FromFile(@"C:\Users\Administrator\Desktop\p_w_picpaths\Google.jpg");
Spire.Doc.Fields.DocPicture picture =para.AppendPicture(p_w_picpath);
para.AppendHyperlink("www.google.com", picture, HyperlinkType.WebLink);

步驟四:保存文檔

doc.SaveToFile("圖片超鏈接.docx", FileFormat.Docx2013);

C# 如何添加文本和圖片超鏈接到Word

以上是利用C#編程語言對如何添加文本及圖片超鏈接的代碼操作演示,希望上述方法對你有所幫助,感謝閱讀!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI