locked
How to add hyperlink to a local file in excel cell using Microsoft.Office.Interop.Excel library? RRS feed

  • Question

  • I know how to create hyperlink in excel . But, it works only when there is no special character in path, which is not allowed is a URL .So, how do I specify that the hyperlink is for a local path and not a server path.Please, find below the code that I am using:

    xlWorkSheet.Hyperlinks.Add(xlWorkSheet.Cells[rowCount + 1, index + 1], hyperlink, Type.Missing, cellValue, cellValue);

    In, some cases it open only part of the path in windows explorer ,and in some cases it gives "address not valid error".

    Friday, November 11, 2016 10:26 AM

Answers

  • Hi VK,

    For # char in Excel hyperlink, it is not supported and it is an known issue. I suggest you remove # from Folder Name.

    You could refer the link below for more information.

    # You cannot use a pound character in a file name for a hyperlink in an Office program https://support.microsoft.com/en-us/kb/202261

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, November 21, 2016 9:32 AM

All replies

  • Hi VK_18,

    Which language do you using?
    Where have you written your code?

    Regards,
    Ashidacchi
    Saturday, November 12, 2016 1:32 AM
  • I am developing a WPF c# application.
    Saturday, November 12, 2016 6:23 AM
  • Hi VK,

    Could you share us value for hyperlink? I made a test with local path, it works at my side.

    ws.Hyperlinks.Add(ws.Cells[1, 1], @"D:\OfficeDev\Test.pdf", Type.Missing, "Test", "Test");

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 14, 2016 5:09 AM
  • Here is the path local path for which hyperlink doesn't work.

    D:\Extraction\#3-Closeout\Andrews Documents\sample.doc

    Monday, November 21, 2016 7:47 AM
  • Hi VK,

    For # char in Excel hyperlink, it is not supported and it is an known issue. I suggest you remove # from Folder Name.

    You could refer the link below for more information.

    # You cannot use a pound character in a file name for a hyperlink in an Office program https://support.microsoft.com/en-us/kb/202261

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, November 21, 2016 9:32 AM
  • But, in case of excel 2016, normal hyperlinks not containing # or pound also don't work.e.g. "C:\ 1 New Community Center Way (CM)-Closeout\ARCHITECTURAL\bridgedesign001.jpg". I get the popup saying "This app can't be activated by the built in administarator". After clicking on Ok , I get  a popup  saying unexpected error occurred.

    Monday, November 21, 2016 1:01 PM
  • Hi VK,

    For this error, it seems your computer has trouble to open jpg file. I suggest you open the jpg file directly by double click to check whether it could be opened.

    To check whether it is related with file path, I suggest you copy your jpg file to root of D: disk, and check whether this issue still exist.

    To check whether it is related with Excel library to add hyperlink, I suggest you manually add hyperlink with these files to check whether it will work.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 22, 2016 5:10 AM
  • Yes, you are right, thanks for the help. But, is there any work going on to fix the issue regarding special characters in hyperlink?
    Tuesday, November 22, 2016 10:53 AM
  • Hi VK,

    I am not sure whether this issue is in progress, but I think you could submit a feedback in the link below.

    https://excel.uservoice.com/

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 23, 2016 3:58 AM
  • Thanks.
    Wednesday, November 23, 2016 7:58 AM