To add hyperlinks to cells in a spreadsheet, take the following steps:
  1. Set up the worksheet:
    • Instantiate an Application object.(VSTO only.)
    • Add a Workbook.
    • Get the first sheet.
    • Add text to the cells that you'll add a hyperlink to.
  2. Add hyperlink.
  3. Save the document.

These steps are shown in the code examples below. The first examples shows how to use VSTO with either C# to add a hyperlink to a cell. The examples that follow show how to do the same thing using Aspose.Cells for .NET, again using C#.

The code samples generate an Excel file that has a hyperlink in cell A1 on the first worksheet.

A hyperlink is added to cell A1.


 //Instantiate the Application object.
            Excel.Application ExcelApp = Application;
            //Add a Workbook.
            Excel.Workbook objBook = ExcelApp.Workbooks.Add(System.Reflection.Missing.Value);
            //Get the First sheet.
            Excel.Worksheet objSheet = (Excel.Worksheet)objBook.Sheets["Sheet1"];

            //Define a range object(A1).
            Excel.Range _range;
            _range = objSheet.get_Range("A1", "A1");
            //Add a hyperlink to it.
            objSheet.Hyperlinks.Add(_range, "", Type.Missing, "Click to go to Aspose site", "Aspose Site!");

            //Save the excel file.
            //Quit the Application.


 //Instantiate a new Workbook object.
            Workbook workbook = new Workbook();
            //Get the First sheet.
            Worksheet worksheet = workbook.Worksheets[0];

            //Define A1 Cell.
            Aspose.Cells.Cell cell = worksheet.Cells["A1"];
            //Add a hyperlink to it.
            int index = worksheet.Hyperlinks.Add("A1", 1, 1, "");
            worksheet.Hyperlinks[index].TextToDisplay = "Aspose Site!";
            worksheet.Hyperlinks[index].ScreenTip = "Click to go to Aspose site";

            //Save the excel file.


*Sample Code

Last edited Jan 1, 2014 at 6:19 AM by asposemarketplace, version 3