Try to import an excel file into xamgrid, but can't get right data for datatime.
in excel cell, the data like: 2012-10-10.
Code to import excel file: use OpenFileDialog to open excel file, then get data in Workbook. but data for above cell is: value =41223.0 , type = object{double}. The code is something like:
TestDate = DateTime.Parse(row.Cells[3].Value.ToString())
and this code stop the app.
How to resolve this problem?
Dates are actually stored as numbers in an Excel file. Excel only displays them as dates to the user because the format string on the cell is set so that the number converts to a date. If you are using the 12.1 version of the Excel library, you can now use the GetText(...) method on cells to get the date string. Otherwise, you will need to look at the FormatString property on the cell format returned from a cell's GetResolvedCellFormat() method. If it is a date format string, you can use the ExcelCalcValue.ExcelDateToDateTime(...) static methods to convert the number to a DateTime.
Actually I use DateTime.FromOADate as the solution. Thanks.