Skip to content

Commit

Permalink
Merge pull request #440 from igitur/allow-formulae-that-start-with-eq…
Browse files Browse the repository at this point in the history
…uals-plus

Allow ridiculous, but valid formulas, e.g. =+++++++MID(A3,3,5)
  • Loading branch information
igitur committed Aug 23, 2017
2 parents b6ea4fd + c9cbe32 commit 76bfc86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ClosedXML/Excel/CalcEngine/CalcEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ public Expression Parse(string expression)

// skip leading equals sign
if (_len > 0 && _expr[0] == '=')
{
_ptr++;
}

// skip leading +'s
while (_len > _ptr && _expr[_ptr] == '+')
_ptr++;

// parse the expression
var expr = ParseExpression();
Expand Down
17 changes: 17 additions & 0 deletions ClosedXML_Tests/Excel/Misc/FormulaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,22 @@ public void FormulaThatReferencesEntireColumn()
Assert.AreEqual(6, actual);
}
}

[Test]
public void FormulaThatStartsWithEqualsAndPlus()
{
object actual;
actual = XLWorkbook.EvaluateExpr("=MID(\"This is a test\", 6, 2)");
Assert.AreEqual("is", actual);

actual = XLWorkbook.EvaluateExpr("=+MID(\"This is a test\", 6, 2)");
Assert.AreEqual("is", actual);

actual = XLWorkbook.EvaluateExpr("=+++++MID(\"This is a test\", 6, 2)");
Assert.AreEqual("is", actual);

actual = XLWorkbook.EvaluateExpr("+MID(\"This is a test\", 6, 2)");
Assert.AreEqual("is", actual);
}
}
}

0 comments on commit 76bfc86

Please sign in to comment.