This closes #1569, formula function CONCAT, CONCATENATE support concatenation of multiple cell values

This commit is contained in:
xuri 2023-07-06 10:49:49 +00:00 committed by GitHub
parent e2c7416292
commit fb72e56667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 18 deletions

21
calc.go
View File

@ -13282,24 +13282,13 @@ func (fn *formulaFuncs) CONCATENATE(argsList *list.List) formulaArg {
// concat is an implementation of the formula functions CONCAT and // concat is an implementation of the formula functions CONCAT and
// CONCATENATE. // CONCATENATE.
func (fn *formulaFuncs) concat(name string, argsList *list.List) formulaArg { 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() { for arg := argsList.Front(); arg != nil; arg = arg.Next() {
token := arg.Value.(formulaArg) for _, cell := range arg.Value.(formulaArg).ToList() {
switch token.Type { if cell.Type == ArgError {
case ArgString: return cell
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())
} }
default: buf.WriteString(cell.Value())
return newErrorFormulaArg(formulaErrorVALUE, fmt.Sprintf("%s requires arguments to be strings", name))
} }
} }
return newStringFormulaArg(buf.String()) return newStringFormulaArg(buf.String())

View File

@ -1663,8 +1663,12 @@ func TestCalcCellValue(t *testing.T) {
"=CODE(\"\")": "0", "=CODE(\"\")": "0",
// CONCAT // CONCAT
"=CONCAT(TRUE(),1,FALSE(),\"0\",INT(2))": "TRUE1FALSE02", "=CONCAT(TRUE(),1,FALSE(),\"0\",INT(2))": "TRUE1FALSE02",
"=CONCAT(MUNIT(2))": "1001",
"=CONCAT(A1:B2)": "1425",
// CONCATENATE // CONCATENATE
"=CONCATENATE(TRUE(),1,FALSE(),\"0\",INT(2))": "TRUE1FALSE02", "=CONCATENATE(TRUE(),1,FALSE(),\"0\",INT(2))": "TRUE1FALSE02",
"=CONCATENATE(MUNIT(2))": "1001",
"=CONCATENATE(A1:B2)": "1425",
// EXACT // EXACT
"=EXACT(1,\"1\")": "TRUE", "=EXACT(1,\"1\")": "TRUE",
"=EXACT(1,1)": "TRUE", "=EXACT(1,1)": "TRUE",
@ -3665,9 +3669,11 @@ func TestCalcCellValue(t *testing.T) {
"=CODE()": {"#VALUE!", "CODE requires 1 argument"}, "=CODE()": {"#VALUE!", "CODE requires 1 argument"},
"=CODE(1,2)": {"#VALUE!", "CODE requires 1 argument"}, "=CODE(1,2)": {"#VALUE!", "CODE requires 1 argument"},
// CONCAT // 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
"=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
"=EXACT()": {"#VALUE!", "EXACT requires 2 arguments"}, "=EXACT()": {"#VALUE!", "EXACT requires 2 arguments"},
"=EXACT(1,2,3)": {"#VALUE!", "EXACT requires 2 arguments"}, "=EXACT(1,2,3)": {"#VALUE!", "EXACT requires 2 arguments"},