Skip to content

Commit

Permalink
Fixed issue 376. Also fixed problem with localization of datetime uni…
Browse files Browse the repository at this point in the history
…ttests for .net core
  • Loading branch information
swmal committed Dec 22, 2018
1 parent d3c0492 commit ad5f709
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 46 deletions.
50 changes: 35 additions & 15 deletions EPPlus/DataValidation/ExcelDataValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,41 @@ internal ExcelDataValidation(ExcelWorksheet worksheet, string address, ExcelData
private void Init()
{
// set schema node order
SchemaNodeOrder = new string[]{
"type",
"errorStyle",
"operator",
"allowBlank",
"showInputMessage",
"showErrorMessage",
"errorTitle",
"error",
"promptTitle",
"prompt",
"sqref",
"formula1",
"formula2"
};
if(ValidationType == ExcelDataValidationType.List)
{
SchemaNodeOrder = new string[]{
"type",
"errorStyle",
"allowBlank",
"showInputMessage",
"showErrorMessage",
"errorTitle",
"error",
"promptTitle",
"prompt",
"sqref",
"formula1"
};
}
else
{
SchemaNodeOrder = new string[]{
"type",
"errorStyle",
"operator",
"allowBlank",
"showInputMessage",
"showErrorMessage",
"errorTitle",
"error",
"promptTitle",
"prompt",
"sqref",
"formula1",
"formula2"
};
}

}

private string CheckAndFixRangeAddress(string address)
Expand Down
17 changes: 8 additions & 9 deletions EPPlus/DataValidation/ExcelDataValidationOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ namespace OfficeOpenXml.DataValidation
/// </summary>
public enum ExcelDataValidationOperator
{
any,
equal,
notEqual,
lessThan,
lessThanOrEqual,
greaterThan,
greaterThanOrEqual,
between,
notBetween
between = 0,
equal = 2,
greaterThan = 6,
greaterThanOrEqual = 7,
lessThan = 4,
lessThanOrEqual = 5,
notBetween = 1,
notEqual= 3
}
}
2 changes: 1 addition & 1 deletion EPPlus/DataValidation/ExcelDataValidationWithFormula.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public T Formula
public override void Validate()
{
base.Validate();
if (Operator == ExcelDataValidationOperator.between || Operator == ExcelDataValidationOperator.notBetween)
if (ValidationType != ExcelDataValidationType.List && (Operator == ExcelDataValidationOperator.between || Operator == ExcelDataValidationOperator.notBetween))
{
if (string.IsNullOrEmpty(Formula2Internal))
{
Expand Down
17 changes: 17 additions & 0 deletions EPPlusTest/Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2326,5 +2326,22 @@ public void Issue348()
var t2 = ws.Cells[2, 5].FormulaR1C1; // VLOOKUP(C2,C[-3]**:B:C:C**,1,0) //unexpected value here
}
}

[TestMethod]
public void Issue376()
{
using (ExcelPackage pck = new ExcelPackage())
{
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("test");
var v = ws.DataValidations.AddListValidation("A1");
v.Formula.Values.Add("1");
v.Formula.Values.Add("2");
v.ShowErrorMessage = true;
v.Error = "error!";
v.ErrorStyle = OfficeOpenXml.DataValidation.ExcelDataValidationWarningStyle.stop;
v.AllowBlank = false;
pck.SaveAs(new FileInfo(@"c:\temp\book.xlsx"));
}
}
}
}
71 changes: 50 additions & 21 deletions EPPlusTest/WorkSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3002,44 +3002,73 @@ public void CommentShiftsWithColumnInserts()
Assert.AreEqual("Testing comment 2", ws1.Cells[3, 8].Comment.Text);
Assert.AreEqual("test2", ws1.Cells[3, 8].Comment.Author);
}
#endregion
#endregion

[TestMethod]
public void DateFunctionsWorkWithDifferentCultureDateFormats()
public void DateFunctionsWorkWithDifferentCultureDateFormats_US()
{
var currentCulture = CultureInfo.CurrentCulture;
#if Core
var us = CultureInfo.DefaultThreadCurrentCulture=new CultureInfo("en-US");
var us = CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
#else
var us = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentCulture = us;
#endif
using (var package = new ExcelPackage())
double usEoMonth = 0d, usEdate = 0d;
var thread = new Thread(delegate ()
{
var ws = package.Workbook.Worksheets.Add("Sheet1");
ws.Cells[2, 2].Value = "1/15/2014";
ws.Cells[3, 3].Formula = "EOMONTH(C2, 0)";
ws.Cells[2, 3].Formula = "EDATE(B2, 0)";
ws.Calculate();
Assert.AreEqual(41654.0, ws.Cells[2, 3].Value);
Assert.AreEqual(41670.0, ws.Cells[3, 3].Value);
}
using (var package = new ExcelPackage())
{
var ws = package.Workbook.Worksheets.Add("Sheet1");
ws.Cells[2, 2].Value = "1/15/2014";
ws.Cells[3, 3].Formula = "EOMONTH(C2, 0)";
ws.Cells[2, 3].Formula = "EDATE(B2, 0)";
ws.Calculate();
usEoMonth = Convert.ToDouble(ws.Cells[2, 3].Value);
usEdate = Convert.ToDouble(ws.Cells[3, 3].Value);

}
});
thread.Start();
thread.Join();
Assert.AreEqual(41654.0, usEoMonth);
Assert.AreEqual(41670.0, usEdate);
#if Core
CultureInfo.DefaultThreadCurrentCulture = currentCulture;
#else
Thread.CurrentThread.CurrentCulture = currentCulture;
#endif
}

[TestMethod]
public void DateFunctionsWorkWithDifferentCultureDateFormats_GB()
{
var currentCulture = CultureInfo.CurrentCulture;

#if Core
var gb = CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-GB");
#else
var gb = CultureInfo.CreateSpecificCulture("en-GB");
Thread.CurrentThread.CurrentCulture = gb;
#endif
using (var package = new ExcelPackage())
double gbEoMonth = 0d, gbEdate = 0d;
var thread = new Thread(delegate ()
{
var ws = package.Workbook.Worksheets.Add("Sheet1");
ws.Cells[2, 2].Value = "15/1/2014";
ws.Cells[3, 3].Formula = "EOMONTH(C2, 0)";
ws.Cells[2, 3].Formula = "EDATE(B2, 0)";
ws.Calculate();
Assert.AreEqual(41654.0, ws.Cells[2, 3].Value);
Assert.AreEqual(41670.0, ws.Cells[3, 3].Value);
}
using (var package = new ExcelPackage())
{
var ws = package.Workbook.Worksheets.Add("Sheet1");
ws.Cells[2, 2].Value = "15/1/2014";
ws.Cells[3, 3].Formula = "EOMONTH(C2, 0)";
ws.Cells[2, 3].Formula = "EDATE(B2, 0)";
ws.Calculate();
gbEoMonth = Convert.ToDouble(ws.Cells[2, 3].Value);
gbEdate = Convert.ToDouble(ws.Cells[3, 3].Value);
}
});
thread.Start();
thread.Join();
Assert.AreEqual(41654.0, gbEoMonth);
Assert.AreEqual(41670.0, gbEdate);
#if Core
CultureInfo.DefaultThreadCurrentCulture = currentCulture;
#else
Expand Down

0 comments on commit ad5f709

Please sign in to comment.