我使用 Microsoft.Office.Interop.Excel 上传了一个 Excel 电子表格。当我尝试读取具有日期值的单元格以便将其插入我的数据集中时,它不会被识别为日期并且它会作为随机数出现?
这是我指代细胞的方式:
Excel.Range startDate = objsheet.get_Range("C1:C" + lastUsedRow, System.Type.Missing);
double dbl = Convert.ToDouble(startDate);
DateTime conv = DateTime.FromOADate(dbl);
(row[3] = ((Microsoft.Office.Interop.Excel.Range)objsheet.Cells[rowIndex, 4]).Value2;)
最佳答案
来自 https://stackoverflow.com/a/4538367/1397117
You need to convert the date format from OLE Automation to the .net format by using DateTime.FromOADate.
double d = double.Parse(b); DateTime conv = DateTime.FromOADate(d);
我在该答案下方回应使用
.Value
的建议而不是 .Value2
.
关于C# 不从电子表格中读取 excel 日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17927250/