This project has moved and is read-only. For the latest updates, please go here.

Hyperlinks - Working for XL2010 but not for XL2007

Jul 25, 2011 at 11:00 PM


        Dim wb As New XLWorkbook()
        Dim ws = wb.Worksheets.Add("Hyperlinks")
        ws.Cell(1, 1).Value = "Link to a file - same folder"
        ws.Cell(1, 1).Hyperlink = New XLHyperlink("C:\Users\Me\Downloads\Whatever\File")

will not work for XL2007. Opening the file leads to recovery and hyperlink removal:

Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.
Repaired Part: /xl/worksheets/sheet.xml part.
Removed Feature: Hyperlinks from /xl/worksheets/sheet.xml part


But it works for XL2010 - The hyperlink refers to file:///C:\Users\Me\Downloads\Whatever\File


Any clue? thx, Peter

Jul 27, 2011 at 6:12 PM

The problem is that Excel 2007 doesn't like absolute addresses. You'll have to use the HYPERLINK formula if you don't want relative addresses:

worksheet.Cell(1, 1).FormulaA1 = "=HYPERLINK(""C:\Folder\File.txt"")";

Jul 28, 2011 at 12:38 PM

Well i checked the files when i create the Hyperlinks within Excel. They are identical for the link. Then i checked the file created by ClosedXML and the XL2010.

Here is the difference:

ClosedXML:  Target="C:\Users\Me\Downloads\Whatever\File"

XL2010:        Target="file:///C:\Users\Me\Downloads\Whatever\File"

So it seems that XL2010 can handle the incomplete URI and changes it internally to the correct format. The next save will fix the issue and XL2007 is also able to open the file.


I changed my coding to get it fixed to:

Dim uri As New Uri("C:\Users\Me\Downloads\Whatever\File")
ws.Cell(1, 1).Hyperlink = New XLHyperlink(uri.AbsoluteUri)
Jul 29, 2011 at 5:48 AM

Fixed it. It will work as expected now.