Fixed small issues when reading Excel files using ClosedXML
This commit is contained in:
parent
e8b094b700
commit
f2a9bc9e0f
@ -562,6 +562,11 @@ namespace ENI2.Excel
|
||||
{
|
||||
result = cellValue.GetDateTime();
|
||||
}
|
||||
else if (cellValue.IsTimeSpan)
|
||||
{
|
||||
TimeSpan timespan = cellValue.GetTimeSpan();
|
||||
result = new DateTime(timespan.Ticks);
|
||||
}
|
||||
else if (cellValue.IsNumber)
|
||||
{
|
||||
double numValue = 0;
|
||||
@ -774,7 +779,7 @@ namespace ENI2.Excel
|
||||
string dateString = ReadCellAsText(sheetName, range);
|
||||
if (dateString != null)
|
||||
{
|
||||
string[] formats = { "yyyy/MM/dd HH:mm", "yyyy/MM/dd", "dd.MM.yyyy", "dd-MM-yyyy", "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "dd/MM/yyyy", "d/MMM/yyyy", "dd/MMM/yyyy", "yyyy-MM-dd", "yyyy-mm-d" };
|
||||
string[] formats = { "yyyy/MM/dd HH:mm", "yyyy/MM/dd", "dd.MM.yyyy", "dd-MM-yyyy", "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "dd/MM/yyyy", "d/MMM/yyyy", "dd/MMM/yyyy", "yyyy-MM-dd", "yyyy-MM-d", "dd.MM.yyyy HH:mm:ss", "dd.MM.yyyy HH:mm" };
|
||||
if (DateTime.TryParseExact(dateString, formats, NumberFormatInfo.InvariantInfo, DateTimeStyles.None, out DateTime tmpDate))
|
||||
return tmpDate;
|
||||
CultureInfo en = CultureInfo.CreateSpecificCulture("en-US");
|
||||
|
||||
@ -1702,7 +1702,7 @@ namespace ENI2.Excel
|
||||
|
||||
string s = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", 54 + i));
|
||||
// All invalid codes become "0000", Oct/25
|
||||
l10fc.PortFacilityGISISCode = (s != null) && Regex.IsMatch(s.Trim(), @"^\d{4}$") ? s.Trim() : "0000";
|
||||
l10fc.PortFacilityGISISCode = (s != null) && Regex.IsMatch(s.Trim(), @"^\d{1,4}$") ? s.Trim().PadLeft(4, '0') : "0000";
|
||||
|
||||
l10fc.PortFacilitySecurityMattersToReport = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", 54 + i), 255);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user