How to use c#vb.net add hyperlink into word

960 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
960
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

How to use c#vb.net add hyperlink into word

  1. 1. How to Use C#/VB.NET Add Hyperlink in WordWhy Add Hyperlink in Word?Hyperlink is an element in an electronic document that links to another place in the samedocument or to an entirely different document. Typically, you click on the hyperlink to follow thelink. Hyperlinks are the most essential ingredient of all hypertext systems, including the WorldWide Web. And Microsoft Word is the most popular program for us to design and edit content.Add hyperlink in Word can easily link to other place by simply press “Ctrl” and right click.In Microsoft Word, it’s easy to add hyperlink. Select the text or picture that you want to display asthe hyperlink. On the Insert tab, in the Links group, click Hyperlink. To link to an existing file orWeb page, click Existing File or Web Page under Link to, and then type the address that you wantto link to in the Address box. If you dont know the address for a file, click the arrow in the Lookin list, and then navigate to the file that you want.On the other hand, by using C#/VB.NET, you also can add hyperlink in Word and you are notnecessary to install Microsoft Office in your system.How to Use C# Add Hyperlink in WordSpire.Doc is a Word Component which enables user to perform a wide range of Word documentprocessing tasks directly for .NET and Silverlight which presents a simply way to use Wordhyperlink, including add hyperlink in Word.Download Spire.Doc (or Spire.Office which includes Spire.Doc) with .NET framework together.Suppose we have written a word document which we want to add hyperlinks. We can useparagraph.AppendHyperlink method to insert hyperlinks. In paragraph.AppendHyperlink methodwe give it three parameters. The first one is the text of the hyperlink, the second is the address ofthe hyperlink and the last is the format of the hyperlink.C# add hyperlinks in word:01 using Spire.Doc;02 using Spire.Doc.Documents;0304 namespace Hyperlink05 {06 class Program07 {08 static void Main(string[] args)09 {10 //Create word document
  2. 2. 11 Document document = new Document();1213 //Create section14 Section section = document.AddSection();1516 //Add paragraph17 Paragraph paragraph = section.AddParagraph();1819 //Append text20 paragraph.AppendText("Spire.XLS for .NET rn e-iceblue company Ltd. 2002-2010All rights reserverd");21 paragraph.ApplyStyle(BuiltinStyle.Heading2);22 paragraph = section.AddParagraph();23 paragraph.AppendText("Home page");24 paragraph.ApplyStyle(BuiltinStyle.Heading2);2526 //Add paragraph27 paragraph = section.AddParagraph();2829 //Insert a weblink30 paragraph.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com",HyperlinkType.WebLink);3132 //Append text33 paragraph = section.AddParagraph();34 paragraph.AppendText("Contact US");35 paragraph.ApplyStyle(BuiltinStyle.Heading2);3637 //Add paragraph38 paragraph = section.AddParagraph();3940 //Insert an Emaillink41 paragraph.AppendHyperlink("mailto:support@e-iceblue.com", "support@e-iceblue.com", HyperlinkType.EMailLink);4243 //Save the file.44 document.SaveToFile("Sample.doc", FileFormat.Doc);4546 //Launching the file.47 System.Diagnostics.Process.Start("Sample.doc");48 }49 }50 }
  3. 3. How to Use VB.NET Add Hyperlink in Word01 Imports Spire.Doc02 Imports Spire.Doc.Documents0304 Module Module10506 Sub Main()07 Create word document08 Dim document As New Document()0910 Create section11 Dim section As Section = document.AddSection()1213 Add paragraph14 Dim paragraph As Paragraph = section.AddParagraph()1516 Append text17 paragraph.AppendText("Spire.XLS for .NET " & vbCrLf & " e-iceblue company Ltd.2002-2010 All rights reserverd")18 paragraph.ApplyStyle(BuiltinStyle.Heading2)19 paragraph = section.AddParagraph()20 paragraph.AppendText("Home page")21 paragraph.ApplyStyle(BuiltinStyle.Heading2)2223 Add paragraph24 paragraph = section.AddParagraph()2526 Insert a weblink27 paragraph.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com",HyperlinkType.WebLink)2829 Add paragraph30 paragraph = section.AddParagraph()3132 Append text33 paragraph.AppendText("Contact US")34 paragraph.ApplyStyle(BuiltinStyle.Heading2)3536 Add paragraph37 paragraph = section.AddParagraph()3839 Insert an Emaillink40 paragraph.AppendHyperlink("mailto:support@e-iceblue.com", "support@e-
  4. 4. iceblue.com", HyperlinkType.EMailLink)4142 Save the file.43 document.SaveToFile("Sample.doc")4445 Launch the file.46 System.Diagnostics.Process.Start("Sample.doc")47 End Sub48 End ModuleScreenshot after running the code above:More about Spire.DocDownload Spire.DocPurchase Spire.Doc

×