Add hyperlink to jump to specific section on the worksheet in .NET

Hi,

Is there a way to add hyperlink to text in cells that would take the user to the specific section on the sheet in excel? I want to add hyperlinks to the text inside of the cells that would take the user to the bottom of the sheet. Since the data on the sheet is being dynamically genereted so it is not possible to know where that specific section at the bottom of the sheet would end up showing.

Or may be jump to the footer of the sheet if footer is present at the bottom of the sheet?

Thanks for your help..

Hi Tom,

Thank you for using Aspose products, and welcome to Aspose.Cells support forum.

You can use the Worksheet.Hyperlinks.Add method to add a hyperlink that can point to any web location (URL) as well as some cell that can be present in same worksheet or any other worksheet within the same workbook.

Simplest code to add a hyperlink is as follow,

C#


worksheet.Hyperlinks.Add(“A1”, 1, 1, “sheet1!D26”);


As you have mentioned that in your scenario the data is dynamically populated in the worksheet therefore you have to calculate the bottom of your worksheet at run time. You can use the Cells.MaxDataRow for this purpose and create a hyperlink that points to the bottom of your worksheet.

Please check the below provided complete code snippet that achieves your requirement. Also attached is the output spreadsheet for your reference.

C#

Workbook book = new Workbook(myDir + "book1.xlsx"); Worksheet sheet = book.Worksheets[0]; sheet.Hyperlinks.Add("A1", 1, 1, sheet.Name + "!"+ CellsHelper.ColumnIndexToName(sheet.Cells.MaxDataColumn)+sheet.Cells.MaxDataRow); book.Save(myDir + "output.xlsx");


Please check the related technical article.
http://www.aspose.com/docs/display/cellsnet/Managing+Hyperlinks+in+a+Worksheet