原創(chuàng)|使用教程|編輯:胡濤|2022-11-23 11:11:49.947|閱讀 139 次
概述:本文將向您展示如何使用 Spire.Doc 在 Word 文檔中創(chuàng)建圖像超鏈接。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for .NET是一款專門對(duì) Word 文檔進(jìn)行操作的 .NET 類庫(kù)。在于幫助開發(fā)人員無(wú)需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗(yàn)Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
使用鏈接圖像,您可以在用戶單擊圖像時(shí)將他們定向到 URL。本文將向您展示如何使用 Spire.Doc 在 Word 文檔中創(chuàng)建圖像超鏈接。
第一步:創(chuàng)建一個(gè)Word文檔,添加一個(gè)節(jié)和一個(gè)段落。
Document doc = new Document(); Section section = doc.AddSection(); Paragraph paragraph = section.AddParagraph();
第 2 步:將圖像加載到 DocPicture 對(duì)象。
DocPicture picture = new DocPicture(doc); picture.LoadImage(Image.FromFile("logo.png"));
第 3 步:向段落添加圖像超鏈接。
paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink);
第 4 步:保存文件。
doc.SaveToFile("output.docx", FileFormat.Docx);
輸出:
完整代碼:
[C#]
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing; namespace CreateLink { class Program { static void Main(string[] args) { Document doc = new Document(); Section section = doc.AddSection(); Paragraph paragraph = section.AddParagraph(); Image image = Image.FromFile("logo.png"); DocPicture picture = new DocPicture(doc); picture.LoadImage(image); paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink); doc.SaveToFile("output.docx", FileFormat.Docx); } } }
[VB.NET]
Imports Spire.Doc Imports Spire.Doc.Documents Imports Spire.Doc.Fields Imports System.Drawing Namespace CreateLink Class Program Private Shared Sub Main(args As String()) Dim doc As New Document() Dim section As Section = doc.AddSection() Dim paragraph As Paragraph = section.AddParagraph() Dim image__1 As Image = Image.FromFile("logo.png") Dim picture As New DocPicture(doc) picture.LoadImage(image__1) paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink) doc.SaveToFile("output.docx", FileFormat.Docx) End Sub End Class End Namespace
以上便是如何在C#去除word文檔中的超鏈接,如果您有其他問(wèn)題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請(qǐng)咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn