IkerCelorrio / excellibrary

Automatically exported from code.google.com/p/excellibrary
0 stars 0 forks source link

datetime value + possible fix. #133

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Load a worksheet
2. Get a row :  Row row = sheet.Cells.GetRow(rowIndex);
3. Try to get a row.GetCell(9).DateTimeValue
(which in the test xls file is a datetime.)

What is the expected output? What do you see instead?

A datetime value. An error (due to DateTime not parsing correctly).

(a string returns with a number )

Possible fix:
public DateTime stringDate(string _value)
        {
            double days = double.Parse(_value);
            DateTime test = DateTime.Parse("1899-12-31");
            //Excel counts an extra day for 1900-Feb-29. In reality, 1900 is not a leap year. 
            if (days > 59)
            {
                days--;
            }
            return test.AddDays(days);
        }

(Performing this function on the stringvalue does give the correct time.)

Please provide any additional information below.

version 1.2011.7.30

Original issue reported on code.google.com by develope...@gmail.com on 18 Jun 2012 at 2:11