2
Vote

DateTime as value of a cell loses time

description

As can be seen in Lite.ExcelLibrary.BinaryFileFormat.SharedResource.EncodeDateTime:
 
public double EncodeDateTime(DateTime value)
{
double days = (value - BaseDate).Days;
if (days > 365) days++;
return days;
}
 
time information is omitted.

comments

gius wrote Jul 3, 2012 at 10:13 AM

Dirty workaround seems to be

public double EncodeDateTime(DateTime value)
{
return value.AddYears(-4).AddDays(-1).ToOADate();
}

The correction is because ExcelLite seems to use January 1, 1904 as base date, whereas ToOADate uses January 0 (yes), 1900.

gius wrote Jul 3, 2012 at 10:16 AM

Or you can update WorkbookEncoder.EncodeWorkbook to use

dateMode.Mode = 0;
sharedResource.BaseDate = DateTime.Parse("1899-12-31");

But I don't know if there are any consequences.

wrote Feb 14, 2013 at 7:25 PM

wrote Apr 25, 2013 at 2:16 PM