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

Create Hyperlink to local directory path

Jan 17, 2011 at 8:56 PM
Edited Jan 17, 2011 at 8:57 PM


I'm new to programming c# with Excel and this is my first time learning how to use EPPlus.  I want to add a hyper link to a cell that points to a local file (i.e. "C:\temp\text1.txt") can someone show me an example?

I've tried the followings:


var uri = new Uri(filepath);

worksheet.Cells[i. j].Hyperlink = new ExcelHyperLink(uri.AbsoluteUri);

And it returns a failure when I try to save the worksheet, with message saying "Error saving file C:\temp\temp.xlsx".  It appears there is a null reference in the inner exception.


To solve the problem of saving the file the only work around is if I do

worksheet.Cells[i. j].Hyperlink = new ExcelHyperLink(uri.AbsoluteUri, "text1.txt"); 

which uses reference address instead of URI (I don't know what the difference is).

But when you open the worksheet and go to "Edit Hyperlink" it shows that it is referencing to a cell and not to an existing file or web page. 




Jan 17, 2011 at 9:20 PM


The ExcelHyperlink class is for internal hyperlinks (reference an worksheet cell).

use worksheet.Cells[i. j].Hyperlink = new Uri(filepath); for an external link


Jan 17, 2011 at 9:32 PM

Thanks I appreciate the help, that solve the link problem!  

But just out of curiosity, if ExcelHyperLink is meant for internal reference to another worksheet cell why does it contain the URI parameter?


Jan 18, 2011 at 7:26 PM

For backward compatibility reason. In the first versions (and in ExcelPackage) the Hyperlink property was just an URI, and did not support interal links in an easy way. That's the main reason the ExcelHyperlink had to inherit the URI class.