超链接到同一文件夹中的文件,EPPlus C#

Hyperlink to file in the same folder, EPPlus C#

我正在使用 C# 中的 EPPlus 库。 我正在尝试在指向当前路径中文件的 Excel 文件中添加一个 hyperlink。但我不能写完整路径,因为它是一个可下载的文件夹。这意味着它取决于客户端中文件夹的位置。

我使用了这个代码:

using (ExcelRange rng = ws.Cells[i, 1])
{
    rng.Hyperlink = new Uri("file://.\sss.jpg");
    rng.Value = p.Name;
}

但我收到来自 Uri 行的错误:

Not a valid Uri

有人知道如何将 link 写入同一文件夹中的文件吗?

谢谢!

试试这个:

using (ExcelRange rng = ws.Cells[i, 1])
{
    rng.Hyperlink = new Uri("sss.jpg", UriKind.Relative);
    rng.Value = p.Name;
}

这将创建一个相对 URI。我已经用 EPPlus 对此进行了测试,它确实会查找相对于 Excel 工作簿位置的文件。