diff --git a/ClosedXML/Excel/CalcEngine/Functions/Lookup.cs b/ClosedXML/Excel/CalcEngine/Functions/Lookup.cs index 801a195..dfd6c1b 100644 --- a/ClosedXML/Excel/CalcEngine/Functions/Lookup.cs +++ b/ClosedXML/Excel/CalcEngine/Functions/Lookup.cs @@ -17,7 +17,7 @@ //ce.RegisterFunction("FORMULATEXT", , Formulatext); // Returns the formula at the given reference as text //ce.RegisterFunction("GETPIVOTDATA", , Getpivotdata); // Returns data stored in a PivotTable report ce.RegisterFunction("HLOOKUP", 3, 4, Hlookup); // Looks in the top row of an array and returns the value of the indicated cell - //ce.RegisterFunction("HYPERLINK", , Hyperlink); // Creates a shortcut or jump that opens a document stored on a network server, an intranet, or the Internet + ce.RegisterFunction("HYPERLINK", 1, 2, Hyperlink); // Creates a shortcut or jump that opens a document stored on a network server, an intranet, or the Internet //ce.RegisterFunction("INDEX", , Index); // Uses an index to choose a value from a reference or array //ce.RegisterFunction("INDIRECT", , Indirect); // Returns a reference indicated by a text value //ce.RegisterFunction("LOOKUP", , Lookup); // Looks up values in a vector or array @@ -80,6 +80,13 @@ .Value; } + private static object Hyperlink(List p) + { + String address = p[0]; + String toolTip = p.Count == 2 ? p[1] : String.Empty; + return new XLHyperlink(address, toolTip); + } + private static object Vlookup(List p) { var lookup_value = p[0]; diff --git a/ClosedXML/Excel/CalcEngine/Functions/Text.cs b/ClosedXML/Excel/CalcEngine/Functions/Text.cs index 8ff1da3..bbf58ca 100644 --- a/ClosedXML/Excel/CalcEngine/Functions/Text.cs +++ b/ClosedXML/Excel/CalcEngine/Functions/Text.cs @@ -39,7 +39,6 @@ ce.RegisterFunction("TRIM", 1, Trim); // Removes spaces from text ce.RegisterFunction("UPPER", 1, Upper); // Converts text to uppercase ce.RegisterFunction("VALUE", 1, Value); // Converts a text argument to a number - ce.RegisterFunction("HYPERLINK", 2, Hyperlink); } private static object _Char(List p) @@ -300,13 +299,6 @@ return (string)p[0]; } - private static object Hyperlink(List p) - { - String address = p[0]; - String toolTip = p.Count == 2 ? p[1] : String.Empty; - return new XLHyperlink(address, toolTip); - } - private static object Clean(List p) { var s = (string)p[0]; diff --git a/ClosedXML_Tests/Excel/CalcEngine/LookupTests.cs b/ClosedXML_Tests/Excel/CalcEngine/LookupTests.cs index a18e509..b7b7151 100644 --- a/ClosedXML_Tests/Excel/CalcEngine/LookupTests.cs +++ b/ClosedXML_Tests/Excel/CalcEngine/LookupTests.cs @@ -129,5 +129,20 @@ Assert.Throws(() => workbook.Evaluate(@"=VLOOKUP(20,Data!$B$2:$I$71,9,FALSE)")); } + + [Test] + public void Hyperlink() + { + XLHyperlink hl; + hl = XLWorkbook.EvaluateExpr("HYPERLINK(\"http://github.com/ClosedXML/ClosedXML\")") as XLHyperlink; + Assert.IsNotNull(hl); + Assert.AreEqual("http://github.com/ClosedXML/ClosedXML", hl.ExternalAddress.ToString()); + Assert.AreEqual(string.Empty, hl.Tooltip); + + hl = XLWorkbook.EvaluateExpr("HYPERLINK(\"mailto:jsmith@github.com\", \"jsmith@github.com\")") as XLHyperlink; + Assert.IsNotNull(hl); + Assert.AreEqual("mailto:jsmith@github.com", hl.ExternalAddress.ToString()); + Assert.AreEqual("jsmith@github.com", hl.Tooltip); + } } }