Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Jan 10, 2020 4:57 pm

Please can you confirm if it is possible to have a hyperlink which does not also have accompanying (non-hyperlink) text.

We are testing a solution that replaces specific text in a Word document with hyperlinks. The text is in a table and each table cell contains a single paragraph.

We expected the following code to remove the text and add the hyperlink:

Code: Select all
paragraph.Text = "";
paragraph.AppendHyperlink("url", "url", HyperlinkType.WebLink);


However, the result is normal text "url". No hyperlink!

If we remove paragraph.Text = ""; and simply append the hyperlink it works as expected but leaves the unwanted text.

Jim

md5technical
 
Posts: 2
Joined: Thu Jan 09, 2020 11:23 am

Mon Jan 13, 2020 6:04 am

Hi,

Thanks for your inquiry.
Please refer to the code below to replace the text with hyperlink in Word document. And I have attached my input file and result file here, please check them.
Code: Select all
            Document document = new Document();
            document.LoadFromFile(@"..\Test.docx");

            //find the text you want to replace.
            TextSelection[] selections = document.FindAllString("Test", false, true);

            //define the hyperlink you want to replace with
            String url = "https://www.e-iceblue.com";
            for (int i = selections.Length - 1; i >= 0; i--)
            {
                ITextRange txtRange = selections[i].GetAsOneRange();

                //append the hyperlink
                txtRange.OwnerParagraph.AppendHyperlink(url, url, HyperlinkType.WebLink);
               
                //delete the original text range
                txtRange.OwnerParagraph.ChildObjects.Remove(txtRange);
            }
            document.SaveToFile("result.docx", FileFormat.Docx);

If the code couldn't solve your issue, to help us investigate it accurately, please offer us the following information.
1. Your input Word file.
2. Your desired result file.
You could upload them here or send us(support@e-iceblue.com) via email.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Thu Jan 16, 2020 11:02 am

Thank you. Problem now solved.

md5technical
 
Posts: 2
Joined: Thu Jan 09, 2020 11:23 am

Fri Jan 17, 2020 1:03 am

Hi,

Thanks for your feedback.
Any question, welcome to contact us. Have a nice day.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.Doc