Possible Duplicate:
Reading Datetime value From Excel sheet
I'm trying to read in a DateTime value from an Excel spreadsheet using Interop in C#. I have all times in the 'C' column of my sheet. My code is as follows:
public void addTime(Microsoft.Office.Interop.Excel.Workbook workbook)
{
Excel.Worksheet ws = (Excel.Worksheet)workbook.Worksheets.get_Item("Time Series");
Excel.Range range = ws.UsedRange;
int num = 0;
for (int row = 1; row <= range.Rows.Count; row++ )
{
String dtString = ((Excel.Range)ws.Cells[row, "C"]).Value2.ToString();
DateTime dt = Convert.ToDateTime(dtString);
this.addEdgeInstance(dt);
}
}
Yet this doesn't read in the time. Reading of the string works, but the Convert function does not work. Do I have read in values a different way? Can the values vary? (IE: can I enter '11/11' or '11/11/2011' as Excel recognizes both of these entries as valie DateTime values when working in Excel?)