Skip to content

Commit

Permalink
Specifically disallow cell ranges for CONCATENATE function. To contra…
Browse files Browse the repository at this point in the history
…st with CONCAT function
  • Loading branch information
igitur committed Apr 1, 2019
1 parent b0eee9e commit fb28f5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ClosedXML/Excel/CalcEngine/Functions/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ private static object Concatenate(List<Expression> p)
var sb = new StringBuilder();
foreach (var x in p)
{
if (x is XObjectExpression objectExpression)
throw new CellValueException("This function does not accept cell ranges as parameters.");

sb.Append((string)x);
}
return sb.ToString();
Expand Down
10 changes: 9 additions & 1 deletion ClosedXML_Tests/Excel/CalcEngine/TextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ public void Concatenate_Value()

actual = XLWorkbook.EvaluateExpr(@"Concatenate("""", ""123"")");
Assert.AreEqual("123", actual);

var ws = new XLWorkbook().AddWorksheet();

ws.FirstCell().SetValue(20)
.CellBelow().SetValue("AB")
.CellBelow().SetFormulaA1("=DATE(2019,1,1)")
.CellBelow().SetFormulaA1("=CONCATENATE(A1:A3)");

Assert.Throws<CellValueException>(() => ws.RecalculateAllFormulas());
}

[Test]
Expand Down Expand Up @@ -281,7 +290,6 @@ public void Mid_Value()
Assert.AreEqual("BC", actual);
}


[TestCase("NUMBERVALUE(\"\")", 0d)]
[TestCase("NUMBERVALUE(\"1,234.56\", \".\", \",\")", 1234.56d)]
[TestCase("NUMBERVALUE(\"1.234,56\", \",\", \".\")", 1234.56d)]
Expand Down

0 comments on commit fb28f5c

Please sign in to comment.