Click here to Skip to main content
14,366,827 members
Rate this:
Please Sign up or sign in to vote.
using Docx DLL I've created hyperlinks
where, I tried to customize styles.

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
string.Format
But when string passed as parameter, it automatically changes to default style.
Posted
Updated 21-Mar-17 5:42am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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();
       }
   
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.
Sathya5995 22-Mar-17 5:18am
   
Oh ok. I've gone through discussions, forums, blogs. I couldn't find solution. I'm not sure whether it is possible or not.
Thanks.
Please let me know, If you got to know about this. It would be a great help :)
Karthik_Mahalingam 22-Mar-17 5:20am
   
sure i will let you know if any..

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100