之前写到从Excel中读取时间数据
//读取Excel数据Excel.Application xapp = new Excel.Application();string filepath = txt_Excel.Text;Excel.Workbook xbook = xapp.Workbooks._Open(filepath, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);Excel.Worksheet xsheet = (Excel.Worksheet)xbook.Sheets[1];xapp.DisplayAlerts = false;timeNow2 = xsheet.Cells[1, 4].Value;//获取xsheet中D1数据 ...//关闭Excel应用和进程
获取xsheet中D1数据
timeNow2 = xsheet.Cells[1, 4].Value;//获取xsheet中D1数据
此方法在目标框架.NET Framework 4.5上运行没有问题。
但在目标框架为.NET Framework 4.0,3.5及以下,就会出现错误
因此我们换一种方法:
//获取xsheet中D1数据
timeNow2 = DateTime.Parse(xsheet.UsedRange.Cells.get_Range("D1", Missing.Value).Text.ToString());