forked from p30928647/excelize
This closes #1569, formula function CONCAT, CONCATENATE support concatenation of multiple cell values
This commit is contained in:
parent
e2c7416292
commit
fb72e56667
21
calc.go
21
calc.go
|
@ -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")
|
||||
for _, cell := range arg.Value.(formulaArg).ToList() {
|
||||
if cell.Type == ArgError {
|
||||
return cell
|
||||
}
|
||||
} else {
|
||||
buf.WriteString(token.Value())
|
||||
}
|
||||
default:
|
||||
return newErrorFormulaArg(formulaErrorVALUE, fmt.Sprintf("%s requires arguments to be strings", name))
|
||||
buf.WriteString(cell.Value())
|
||||
}
|
||||
}
|
||||
return newStringFormulaArg(buf.String())
|
||||
|
|
10
calc_test.go
10
calc_test.go
|
@ -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",
|
||||
|
@ -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"},
|
||||
|
|
Loading…
Reference in New Issue