C# Excel how to add hyperlink with cell link
14,018
Solution 1
Use the HYPERLINK
formula?
curSheet.get_Range("c1").Formula = "=HYPERLINK(""https://www.google.ru/?q="" & b1)"
Solution 2
use this code:
Excel.Worksheet sh;
sh.Hyperlinks.Add(sh.Cells[1, 1], "http://www.Sharifsoft.com/", Type.Missing, "Sharifsoft", "www.Sharifsoft.com");
I found this answer in this link
Solution 3
you can try do below this:
var excelApp = new Microsoft.Office.Interop.Excel.Application();
var excelWB = excelApp.Workbooks.Add(Type.Missing);
var excelWS = (Microsoft.Office.Interop.Excel.Worksheet)excelWB.Worksheets[1];
var excelCell = excelWS.get_Range("A1", "A1");
excelWS.Hyperlinks.Add(excelCell, "https://stackoverflow.com/", Type.Missing, "Stackoverflow", "Stackoverflow");
Author by
raccoon
Student of National Aviation University, applied math, Kiyv.
Updated on June 04, 2022Comments
-
raccoon almost 2 years
I`ll try to work with Excel using C#.
I need to add a hyperlink, which using the value of another cell. If this value in document is changed, hyperlink also must change.
This code:
curSheet.Hyperlinks.Add(curSheet.get_Range("c1"), "https://www.google.ru/?q=" + curSheet.get_Range("b1").Value)
will give me a fixed link. How can I create a dynamic link, which contain a sublink to cell, not cell value?