Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ReoGrid/Core/DataFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -928,13 +928,10 @@ public string FormatCell(Cell cell)
{
try
{
var val = (double)number;

// Excel/Lotus 2/29/1900 bug
// original post: http://stackoverflow.com/questions/727466/how-do-i-convert-an-excel-serial-date-number-to-a-net-datetime
if (val > 59) val -= 1;
// original post: http://stackoverflow.com/questions/4538321/reading-datetime-value-from-excel-sheet
value = DateTime.FromOADate(number);

value = BaseStartDate.AddDays(val - 1);
isFormat = true;
}
catch { }
Expand Down Expand Up @@ -974,7 +971,11 @@ public string FormatCell(Cell cell)
{
DateTimeFormatArgs dargs = (DateTimeFormatArgs)cell.DataFormatArgs;

pattern = dargs.Format;
if (pattern == null || pattern == String.Empty)
{
pattern = dargs.Format;
}

culture = (dargs.CultureName == null
|| string.Equals(dargs.CultureName, Thread.CurrentThread.CurrentCulture.Name))
? Thread.CurrentThread.CurrentCulture : new CultureInfo(dargs.CultureName);
Expand Down
13 changes: 8 additions & 5 deletions ReoGrid/IO/ExcelReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ private static CellDataFormatFlag SetRGSheetDataFormat(RGWorksheet rgSheet, Cell
// #,##0.00 [$-419E] #,##0.00
else if ((currencyMatch = currencyFormatRegex.Match(pattern)).Success)
{
#region Currency
#region Currency
flag = CellDataFormatFlag.Currency;
var carg = new CurrencyDataFormatter.CurrencyFormatArgs();

Expand Down Expand Up @@ -1606,21 +1606,24 @@ private static CellDataFormatFlag SetRGSheetDataFormat(RGWorksheet rgSheet, Cell
}

arg = carg;
#endregion // Currency
#endregion // Currency
}
else if (pattern.EndsWith("%"))
{
#region Percent
#region Percent
flag = CellDataFormatFlag.Percent;

pattern = pattern.Substring(0, pattern.Length - 1);

arg = ReadNumberFormatArgs(pattern, new NumberDataFormatter.NumberFormatArgs());
#endregion // Percent
#endregion // Percent
}
else if (pattern.Any(c => c == 'm' || c == 'h' || c == 's' || c == 'y' || c == 'd'))
{
pattern = pattern.Replace("yyyy/mm", "yyyy/MM").Replace("mm/d", "MM/d").Replace("m/d", "M/d").Replace("aaa", "ddd");
pattern = pattern.Replace("yyyy/mm", "yyyy/MM").Replace("mm/yy", "MM/yy")
.Replace("mm/d", "MM/d").Replace("m/d", "M/d")
.Replace("d/mm", "d/MM").Replace("d/m", "d/M")
.Replace("aaa", "ddd");

flag = CellDataFormatFlag.DateTime;

Expand Down