This is a migrated thread and some comments may be shown as answers.

How to add a hyperlink to a table cell

1 Answer 494 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Alexis
Top achievements
Rank 1
Alexis asked on 20 Oct 2017, 05:52 PM
I add a table to my document. I can add text to a table cell and style it (bold, italic, etc), but I don't know how to add a hyperlink to a table cell. All I see is "editor.InsertHyperlink()", but it adds the hyperlink below my table, not in my table cell.

1 Answer, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 23 Oct 2017, 03:42 PM
Hello Alexis,

In order to insert a hyperlink inside a table cell we should first position the editor inside the cell, for example after an empty run in its paragraph.
Then we can call the editor.InsertHyperlink() method which will apply the Hyperlink style to the result fragment of the inserted field.
After that we should move the position of the editor after the table (if this is its last cell) and continue building the document.

The following code snippet demonstrates how you can achieve that:

Table table = document.Sections.First().Blocks.AddTable();
 
TableRow row = table.Rows.AddTableRow();
 
TableCell cell = new TableCell(document);
cell.Blocks.AddParagraph().Inlines.AddRun("link to Telerik.com");
row.Cells.Add(cell);
 
TableCell cell2 = new TableCell(document);
Run linkRun = new Run(document);
cell2.Blocks.AddParagraph().Inlines.Add(linkRun);
row.Cells.Add(cell2);
 
editor.MoveToInlineEnd(linkRun);
Hyperlink hyperlink = editor.InsertHyperlink("https://www.telerik.com", "https://www.telerik.com", false);
 
editor.MoveToTableEnd(table);

Hope this helps.

Regards,
Polya
Progress Telerik

Tags
WordsProcessing
Asked by
Alexis
Top achievements
Rank 1
Answers by
Polya
Telerik team
Share this question
or