How to create a link inside a cell using EPPlus

后端 未结 6 641
醉酒成梦
醉酒成梦 2021-02-01 12:40

I am trying to figure out how to write a Hyperlink inside a cell using EPPlus instead of the cell containing the link text. I need it to be recognized as a link and be clickable

6条回答
  •  日久生厌
    2021-02-01 13:39

    There's a few ways to go about it:

    1) To use URI, then set a human readable name

    var cell = sheet.Cells["A1"];
    cell.Hyperlink = new Uri("http://www.google.com");
    cell.Value = "Click me!";
    

    2) To use ExcelHyperLink and set a human readable name using object initializer

    var cell = sheet.Cells["A1"];
    cell.Hyperlink = new ExcelHyperLink("http://www.google.com") { Display = "Click me! };
    

    3) To use =Hyperlink() formula

    var cell = sheet.Cells["A1"];
    cell.Formula = string.Format("HYPERLINK({0},{1})", "http://www.google.com", "Click me!");
    cell.Calculate();
    

提交回复
热议问题