Adding hyperlink to Excel sheet

Hello,

I am trying to convert some VB.NET code to C# that writes information to an Excel file. What i'm having trouble is that i'm trying to insert a hyperlink to an local file like i did before but i can't seem to get past this exception. Here is my old code.
Dim xlCurrentSheet As Excel.Worksheet
xlCurrentSheet.Range("A3").Offset(yDir - 1).Hyperlinks.Add(xlCurrentSheet.Range("A3").Offset(yDir - 1), OrdPath, , , TextBox1.Text)

here is the new code i'm trying:
oRange = (Excel.Range)currSheet.get_Range("A1", "A100");
string ordPath = @"C:\\IDTWest\\orders\\order" + orderInfo.orderNum.ToString() + ".doc";
Object txtToDis = "order " + orderInfo.orderNum.ToString();
object[,] updateEx = new object[1, 9];

updateEx[0, 0] = (Excel.Range)curSheet.Hyperlinks.Add(oMissing, ordPath, oMissing, oMissing, txtToDis);
oRange.set_Value(oMissing, updateEx);

Am I missing something thanks for the help in advance!


Answer this question

Adding hyperlink to Excel sheet

  • nonamehero

    Hi megadith31,

    To insert a hyperlink into a cell (in this case D5), I used the following code:

    Range range = ((Worksheet) this.ActiveSheet).get_Range("D5", missing);
    Hyperlink hyperlink = (Hyperlink) range.Hyperlinks.Add(range, "http://www.artandparcel.com", missing, missing, "Hyperlink test");

    Hope this helps,

    Jonathan


  • Michael Vainer

    I have same question.

    But i use Visual C++. Not C#.

    how can i use the hyperlink to another sheet.



  • Adding hyperlink to Excel sheet