Skip to content

Commit fb72e56

Browse files
authored
This closes #1569, formula function CONCAT, CONCATENATE support concatenation of multiple cell values
1 parent e2c7416 commit fb72e56

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

calc.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13282,24 +13282,13 @@ func (fn *formulaFuncs) CONCATENATE(argsList *list.List) formulaArg {
1328213282
// concat is an implementation of the formula functions CONCAT and
1328313283
// CONCATENATE.
1328413284
func (fn *formulaFuncs) concat(name string, argsList *list.List) formulaArg {
13285-
buf := bytes.Buffer{}
13285+
var buf bytes.Buffer
1328613286
for arg := argsList.Front(); arg != nil; arg = arg.Next() {
13287-
token := arg.Value.(formulaArg)
13288-
switch token.Type {
13289-
case ArgString:
13290-
buf.WriteString(token.String)
13291-
case ArgNumber:
13292-
if token.Boolean {
13293-
if token.Number == 0 {
13294-
buf.WriteString("FALSE")
13295-
} else {
13296-
buf.WriteString("TRUE")
13297-
}
13298-
} else {
13299-
buf.WriteString(token.Value())
13287+
for _, cell := range arg.Value.(formulaArg).ToList() {
13288+
if cell.Type == ArgError {
13289+
return cell
1330013290
}
13301-
default:
13302-
return newErrorFormulaArg(formulaErrorVALUE, fmt.Sprintf("%s requires arguments to be strings", name))
13291+
buf.WriteString(cell.Value())
1330313292
}
1330413293
}
1330513294
return newStringFormulaArg(buf.String())

calc_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,8 +1663,12 @@ func TestCalcCellValue(t *testing.T) {
16631663
"=CODE(\"\")": "0",
16641664
// CONCAT
16651665
"=CONCAT(TRUE(),1,FALSE(),\"0\",INT(2))": "TRUE1FALSE02",
1666+
"=CONCAT(MUNIT(2))": "1001",
1667+
"=CONCAT(A1:B2)": "1425",
16661668
// CONCATENATE
16671669
"=CONCATENATE(TRUE(),1,FALSE(),\"0\",INT(2))": "TRUE1FALSE02",
1670+
"=CONCATENATE(MUNIT(2))": "1001",
1671+
"=CONCATENATE(A1:B2)": "1425",
16681672
// EXACT
16691673
"=EXACT(1,\"1\")": "TRUE",
16701674
"=EXACT(1,1)": "TRUE",
@@ -3665,9 +3669,11 @@ func TestCalcCellValue(t *testing.T) {
36653669
"=CODE()": {"#VALUE!", "CODE requires 1 argument"},
36663670
"=CODE(1,2)": {"#VALUE!", "CODE requires 1 argument"},
36673671
// CONCAT
3668-
"=CONCAT(MUNIT(2))": {"#VALUE!", "CONCAT requires arguments to be strings"},
3672+
"=CONCAT(NA())": {"#N/A", "#N/A"},
3673+
"=CONCAT(1,1/0)": {"#DIV/0!", "#DIV/0!"},
36693674
// CONCATENATE
3670-
"=CONCATENATE(MUNIT(2))": {"#VALUE!", "CONCATENATE requires arguments to be strings"},
3675+
"=CONCATENATE(NA())": {"#N/A", "#N/A"},
3676+
"=CONCATENATE(1,1/0)": {"#DIV/0!", "#DIV/0!"},
36713677
// EXACT
36723678
"=EXACT()": {"#VALUE!", "EXACT requires 2 arguments"},
36733679
"=EXACT(1,2,3)": {"#VALUE!", "EXACT requires 2 arguments"},

0 commit comments

Comments
 (0)