From dde6b9c00135cefffdd9c64b7f22cfdc34c28e47 Mon Sep 17 00:00:00 2001 From: devloppper <76152313+devloppper@users.noreply.github.com> Date: Tue, 22 Nov 2022 00:14:03 +0800 Subject: [PATCH] This closes #1396, fix formula fn ADDRESS result error with empty worksheet name (#1397) - Update unit tests Co-authored-by: jayhoo --- calc.go | 7 ++----- calc_test.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/calc.go b/calc.go index b4090c9..9c360c1 100644 --- a/calc.go +++ b/calc.go @@ -13960,13 +13960,10 @@ func (fn *formulaFuncs) ADDRESS(argsList *list.List) formulaArg { } var sheetText string if argsList.Len() == 5 { - sheetText = trimSheetName(argsList.Back().Value.(formulaArg).Value()) - } - if len(sheetText) > 0 { - sheetText = fmt.Sprintf("%s!", sheetText) + sheetText = fmt.Sprintf("%s!", trimSheetName(argsList.Back().Value.(formulaArg).Value())) } formatter := addressFmtMaps[fmt.Sprintf("%d_%s", int(absNum.Number), a1.Value())] - addr, err := formatter(int(colNum.Number), int(colNum.Number)) + addr, err := formatter(int(colNum.Number), int(rowNum.Number)) if err != nil { return newErrorFormulaArg(formulaErrorVALUE, formulaErrorVALUE) } diff --git a/calc_test.go b/calc_test.go index 5d61712..1376c00 100644 --- a/calc_test.go +++ b/calc_test.go @@ -1800,14 +1800,23 @@ func TestCalcCellValue(t *testing.T) { // Excel Lookup and Reference Functions // ADDRESS "=ADDRESS(1,1,1,TRUE)": "$A$1", + "=ADDRESS(1,2,1,TRUE)": "$B$1", "=ADDRESS(1,1,1,FALSE)": "R1C1", + "=ADDRESS(1,2,1,FALSE)": "R1C2", "=ADDRESS(1,1,2,TRUE)": "A$1", + "=ADDRESS(1,2,2,TRUE)": "B$1", "=ADDRESS(1,1,2,FALSE)": "R1C[1]", + "=ADDRESS(1,2,2,FALSE)": "R1C[2]", "=ADDRESS(1,1,3,TRUE)": "$A1", + "=ADDRESS(1,2,3,TRUE)": "$B1", "=ADDRESS(1,1,3,FALSE)": "R[1]C1", + "=ADDRESS(1,2,3,FALSE)": "R[1]C2", "=ADDRESS(1,1,4,TRUE)": "A1", + "=ADDRESS(1,2,4,TRUE)": "B1", "=ADDRESS(1,1,4,FALSE)": "R[1]C[1]", - "=ADDRESS(1,1,4,TRUE,\"\")": "A1", + "=ADDRESS(1,2,4,FALSE)": "R[1]C[2]", + "=ADDRESS(1,1,4,TRUE,\"\")": "!A1", + "=ADDRESS(1,2,4,TRUE,\"\")": "!B1", "=ADDRESS(1,1,4,TRUE,\"Sheet1\")": "Sheet1!A1", // CHOOSE "=CHOOSE(4,\"red\",\"blue\",\"green\",\"brown\")": "brown",