From 2e1b0efadc0519fa4572b2437401bf2993366a07 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 24 Jun 2022 01:03:19 +0800 Subject: [PATCH] ref #65, new formula function: HYPERLINK --- calc.go | 15 +++++++++++++++ calc_test.go | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/calc.go b/calc.go index c71cd10..d9bf653 100644 --- a/calc.go +++ b/calc.go @@ -14514,6 +14514,21 @@ func (fn *formulaFuncs) HLOOKUP(argsList *list.List) formulaArg { return newErrorFormulaArg(formulaErrorNA, "HLOOKUP no result found") } +// HYPERLINK function creates a hyperlink to a specified location. The syntax +// of the function is: +// +// HYPERLINK(link_location,[friendly_name]) +// +func (fn *formulaFuncs) HYPERLINK(argsList *list.List) formulaArg { + if argsList.Len() < 1 { + return newErrorFormulaArg(formulaErrorVALUE, "HYPERLINK requires at least 1 argument") + } + if argsList.Len() > 2 { + return newErrorFormulaArg(formulaErrorVALUE, "HYPERLINK allows at most 2 arguments") + } + return newStringFormulaArg(argsList.Back().Value.(formulaArg).Value()) +} + // calcMatch returns the position of the value by given match type, criteria // and lookup array for the formula function MATCH. func calcMatch(matchType int, criteria *formulaCriteria, lookupArray []formulaArg) formulaArg { diff --git a/calc_test.go b/calc_test.go index 2cd5646..b3eb196 100644 --- a/calc_test.go +++ b/calc_test.go @@ -1788,6 +1788,9 @@ func TestCalcCellValue(t *testing.T) { "=HLOOKUP(F3,F3:F8,3,FALSE)": "34440", "=HLOOKUP(INT(F3),F3:F8,3,FALSE)": "34440", "=HLOOKUP(MUNIT(1),MUNIT(1),1,FALSE)": "1", + // HYPERLINK + "=HYPERLINK(\"https://github.com/xuri/excelize\")": "https://github.com/xuri/excelize", + "=HYPERLINK(\"https://github.com/xuri/excelize\",\"Excelize\")": "Excelize", // VLOOKUP "=VLOOKUP(D2,D:D,1,FALSE)": "Jan", "=VLOOKUP(D2,D1:D10,1)": "Jan", @@ -3725,6 +3728,9 @@ func TestCalcCellValue(t *testing.T) { "=MATCH(0,A1:B1)": "MATCH arguments lookup_array should be one-dimensional array", // TRANSPOSE "=TRANSPOSE()": "TRANSPOSE requires 1 argument", + // HYPERLINK + "=HYPERLINK()": "HYPERLINK requires at least 1 argument", + "=HYPERLINK(\"https://github.com/xuri/excelize\",\"Excelize\",\"\")": "HYPERLINK allows at most 2 arguments", // VLOOKUP "=VLOOKUP()": "VLOOKUP requires at least 3 arguments", "=VLOOKUP(D2,D1,1,FALSE)": "VLOOKUP requires second argument of table array",