【问题标题】:Hyperlink to a cell on another workbook - EPPlus超链接到另一个工作簿上的单元格 - EPPlus
【发布时间】:2017-09-29 16:53:33
【问题描述】:

我想向另一个工作簿的单元格添加超链接。我可以引用整个文件,但在引用特定单元格时遇到问题。

生成的超链接格式正确,因为当我在生成的 Excel 文件上单击修改超链接然后单击确定(不修改它)时,超链接开始工作。

我已经尝试过 Uri 的所有构造函数,我尝试计算单元格值,但我没有找到解决方案。这是我的代码。

这行得通:

resultSheet.Cells[currentRow, 10].Hyperlink = new Uri(message.myReference.filePath, UriKind.Absolute);

这在单击修改然后在生成的 Excel 文件上确定后才起作用。

resultSheet.Cells[currentRow, 10].Hyperlink = new Uri(message.myReference.filePath + "#'" + message.myReference.sheetName + "'!" + "A" + message.myReference.cellRow, UriKind.Absolute);

我非常感谢任何形式的帮助,因为我有点陷入这个愚蠢的问题。

【问题讨论】:

    标签: c# excel hyperlink epplus epplus-4


    【解决方案1】:

    我尝试过使用 Interop 库,这对我有用。 也许您可以使用类似的逻辑或想法。

    Range whereHyperLinkWillBe = activeWorksheet.get_Range("O3", Type.Missing);
    string filePathOfHyerlinkDestination = "C:\\Users\\Desktop\\HyerlinkFile.xlsx";
    string hyperlinkTargetAddress = "Sheet1!B4";
    activeWorksheet.Hyperlinks.Add(whereHyperLinkWillBe, filePathOfHyerlinkDestination ,hyperlinkTargetAddress, "Hyperlink Sample", "Hyperlink Title");
    

    【讨论】:

    • 感谢您的帮助!我通过使用 EPPlus 手动创建超链接公式找到了一个解决方案,我会在白天发布它:)
    • @PabloMaldonado 太棒了!干得好!
    【解决方案2】:

    官方的方法是使用new ExcelHyperLink(),见

    ws.Cells["K13"].Hyperlink = new ExcelHyperLink("Statistics!A1", "Statistics");
    

    https://github.com/JanKallman/EPPlus/wiki/Formatting-and-styling

    【讨论】:

      【解决方案3】:

      所以我找到了答案,我可以通过使用单元格的公式属性来做到这一点,方法是添加超链接引用和我想在单元格上显示的值:

      resultSheet.Cells[currentRow, 10].Formula = "HYPERLINK(\"" + filePath + "#'" + sheetName + "'!" + rowLetter + rowNumber + "\",\"" + "message to show on the cell" + "\")";
      resultSheet.Cells[currentRow, 10].Calculate();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-28
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        • 2020-03-04
        • 2019-07-25
        • 1970-01-01
        相关资源
        最近更新 更多