Skip to content

Commit

Permalink
This closes #1569, formula function CONCAT, CONCATENATE support conca…
Browse files Browse the repository at this point in the history
…tenation of multiple cell values
  • Loading branch information
xuri committed Jul 6, 2023
1 parent e2c7416 commit fb72e56
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
21 changes: 5 additions & 16 deletions calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13282,24 +13282,13 @@ func (fn *formulaFuncs) CONCATENATE(argsList *list.List) formulaArg {
// concat is an implementation of the formula functions CONCAT and
// CONCATENATE.
func (fn *formulaFuncs) concat(name string, argsList *list.List) formulaArg {
buf := bytes.Buffer{}
var buf bytes.Buffer
for arg := argsList.Front(); arg != nil; arg = arg.Next() {
token := arg.Value.(formulaArg)
switch token.Type {
case ArgString:
buf.WriteString(token.String)
case ArgNumber:
if token.Boolean {
if token.Number == 0 {
buf.WriteString("FALSE")
} else {
buf.WriteString("TRUE")
}
} else {
buf.WriteString(token.Value())
for _, cell := range arg.Value.(formulaArg).ToList() {
if cell.Type == ArgError {
return cell
}
default:
return newErrorFormulaArg(formulaErrorVALUE, fmt.Sprintf("%s requires arguments to be strings", name))
buf.WriteString(cell.Value())
}
}
return newStringFormulaArg(buf.String())
Expand Down
10 changes: 8 additions & 2 deletions calc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,8 +1663,12 @@ func TestCalcCellValue(t *testing.T) {
"=CODE(\"\")": "0",
// CONCAT
"=CONCAT(TRUE(),1,FALSE(),\"0\",INT(2))": "TRUE1FALSE02",
"=CONCAT(MUNIT(2))": "1001",
"=CONCAT(A1:B2)": "1425",
// CONCATENATE
"=CONCATENATE(TRUE(),1,FALSE(),\"0\",INT(2))": "TRUE1FALSE02",
"=CONCATENATE(MUNIT(2))": "1001",
"=CONCATENATE(A1:B2)": "1425",
// EXACT
"=EXACT(1,\"1\")": "TRUE",
"=EXACT(1,1)": "TRUE",
Expand Down Expand Up @@ -3665,9 +3669,11 @@ func TestCalcCellValue(t *testing.T) {
"=CODE()": {"#VALUE!", "CODE requires 1 argument"},
"=CODE(1,2)": {"#VALUE!", "CODE requires 1 argument"},
// CONCAT
"=CONCAT(MUNIT(2))": {"#VALUE!", "CONCAT requires arguments to be strings"},
"=CONCAT(NA())": {"#N/A", "#N/A"},
"=CONCAT(1,1/0)": {"#DIV/0!", "#DIV/0!"},
// CONCATENATE
"=CONCATENATE(MUNIT(2))": {"#VALUE!", "CONCATENATE requires arguments to be strings"},
"=CONCATENATE(NA())": {"#N/A", "#N/A"},
"=CONCATENATE(1,1/0)": {"#DIV/0!", "#DIV/0!"},
// EXACT
"=EXACT()": {"#VALUE!", "EXACT requires 2 arguments"},
"=EXACT(1,2,3)": {"#VALUE!", "EXACT requires 2 arguments"},
Expand Down

0 comments on commit fb72e56

Please sign in to comment.