Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
using Docx DLL I've created hyperlinks
where, I tried to customize styles.

C#
public Hyperlink AddHyperLink(string name, string uri)
        {
          //FontFamily family = new FontFamily("Comic Sans MS");
          //string Name= string.Format(name,Color.DarkOrange, FontStyle.Regular,family);
            Hyperlink hp = document.AddHyperlink(name, new Uri(uri)); ;

            return hp ;
        }


In Docx Addhyperlink method accteps only two parameters 1) string 2) URI

In novacode.Docx paragrapth only has style method, string has no style features.

how can I have different styles for hyperlink ?

Thanks in advance.

What I have tried:

I tried
C#
string.Format
But when string passed as parameter, it automatically changes to default style.
Posted
Updated 21-Mar-17 4:42am
v2

1 solution

try this

using (DocX document = DocX.Create(path))
       {
           Hyperlink h = document.AddHyperlink    (name, new Uri(uri));
           Paragraph p = document.InsertParagraph();
           p.AppendHyperlink(h).Font(new FontFamily("Comic Sans MS")).FontSize(15).Color(Color.Blue);
           document.Save();
       }
 
Share this answer
 
v2
Comments
Sathya5995 22-Mar-17 2:12am    
Hi Karthik, Thank you so much. I have a scenario where hyperlink has to be inserted in between a paragraph. So I cannot have a paragraph p to create hyperlink.(hyperlink and paragraph will have different styles)
2) by following your solution we can achieve styles, but (underline.none) won't work here. Am I missing something ?

Once again thanks :)
Karthik_Mahalingam 22-Mar-17 2:17am    
try
p.AppendHyperlink(h).Font(new FontFamily("Comic Sans MS")).FontSize(15).Color(Color.Blue).UnderlineColor(Color.Red);
Sathya5995 22-Mar-17 3:10am    
yeah will try.
Thanks :)
Karthik_Mahalingam 22-Mar-17 3:15am    
ok.welcome
Karthik_Mahalingam 22-Mar-17 5:13am    
Hi Sathya
have not tried that, i am not sure, you need to explore the library.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900