I am trying to get the text in a cell through spreadsheet gear library.
There is a formula applied to a column C1 =GETURL(I2)
and it is evaluating text which is something like "https://loremipsum.com/2345/view"
I have another column C2 with a formula which outputs 'View' as Text
=HYPERLINK(CONCATENATE("https://loremipsum.com/",[@[Customer CID]],"/view"), "View")
Now, when i try to get the Text through C# code for cells in C2 column, I get "View" when I run the below statement and "#Name?" for cells in C1 column.
worksheet.Cells[i, j].Text; //Outputs = "#NAME?"
I tried to use =TEXT(GETURL(I2), "")
in excel but still it outputs #Name!
I also tried doing worksheet.Cells[i, j].Value //Output = Name
Why is that the same statement is giving me different results even when both cells are having a formula applied to them.
Function GETURL(cell As Range, Optional default_value As Variant)
With cell.Range("A1")
If .Hyperlinks.Count = 1 Then
GETURL = .Hyperlinks(1).Address
Else
If Left$(Replace(Replace(Replace(.Formula, " ", ""), vbCr, ""), vbLf, ""), 11) = "=HYPERLINK(" Then
Dim indexFirstArgument As Long: indexFirstArgument = InStr(.Formula, "(") + 1
GETURL = Application.Evaluate(Mid$(.Formula, indexFirstArgument, InStrRev(.Formula, ",") - indexFirstArgument))
Else
GETURL = default_value
End If
End If
End With
End Function