Skip to content

Commit

Permalink
#427 - Validation of datavalidations throw an exception when Formula1…
Browse files Browse the repository at this point in the history
… is empty even if AllowBlank was set to true
  • Loading branch information
swmal committed Jul 6, 2021
1 parent 3e342b6 commit 85c1fb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/EPPlus/DataValidation/ExcelDataValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public virtual void Validate()
{
var address = Address.Address;
// validate Formula1
if (string.IsNullOrEmpty(Formula1Internal))
if (string.IsNullOrEmpty(Formula1Internal) && !(AllowBlank ?? false))
{
throw new InvalidOperationException("Validation of " + address + " failed: Formula1 cannot be empty");
}
Expand Down
15 changes: 15 additions & 0 deletions src/EPPlusTest/DataValidation/DataValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ public void DataValidations_ShouldAcceptOneItemOnly()
validation.Validate();
}

[TestMethod]
public void DataValidations_ShouldNotThrowIfAllowBlankIsSet()
{
var validation = _sheet.DataValidations.AddListValidation("A1");
validation.AllowBlank = true;
validation.Validate();
}

[TestMethod, ExpectedException(typeof(InvalidOperationException))]
public void DataValidations_ShouldThrowIfAllowBlankIsNotSet()
{
var validation = _sheet.DataValidations.AddListValidation("A1");
validation.Validate();
}

[TestMethod]
public void ExcelDataValidation_ShouldReplaceLastPartInWholeColumnRangeWithMaxNumberOfRowsOneColumn()
{
Expand Down

0 comments on commit 85c1fb7

Please sign in to comment.