从VB.NET中的Excel文件读取时间返回一个整数

从VB.NET中的Excel文件读取时间返回一个整数,vb.net,datetime-format,Vb.net,Datetime Format,我试图将Excel文件读取到VB.NET应用程序中。读取Excel文件时,文件中的“时间”列不会返回时间格式,而是返回整数,例如: 17:14:04 --> 0.718101852 13:26:12 --> 0.559861111 7:26:29 --> 0.31005787 如何将这些数字转换回时间格式 请帮帮我谢谢试着这样做: Dim dttm As DateTime = (New DateTime()).AddDays(worksheet.Cells(2, 3)) T

我试图将Excel文件读取到VB.NET应用程序中。读取Excel文件时,文件中的“时间”列不会返回时间格式,而是返回整数,例如:

17:14:04 --> 0.718101852
13:26:12 --> 0.559861111
7:26:29  --> 0.31005787
如何将这些数字转换回时间格式

请帮帮我谢谢

试着这样做:

Dim dttm As DateTime = (New DateTime()).AddDays(worksheet.Cells(2, 3))
TextBox1.Text = ddtm.toString()
Dim dt As DateTime = (New DateTime()).AddDays(0.559861111)  
它对我有用。它返回:

13:26:12 from 0.559861111  

我的excel工作表如下所示:

Dim dt As DateTime = (New DateTime()).AddDays(0.559861111)  

我的代码是这样的,它工作得很好

Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook

Dim xlWorkSheet As Excel.Worksheet

Dim DateVal As String, TimeVal As Double, myTime as Date

On Error GoTo OpenCSVfileError

xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(FileName)
xlWorkSheet = xlWorkBook.ActiveSheet

Dim xRng As Excel.Range

xRng = CType(xlWorkSheet.Cells(2, 1), Excel.Range)
DateVal = xRng.Value.ToString
myTime = CDate(DateVal)
xRng = CType(xlWorkSheet.Cells(2, 2), Excel.Range)
TimeVal = CDbl(xRng.Value.ToString)
myTime = myTime.AddDays(TimeVal)
OpenCSVfileError:
        xlWorkBook.Close()
        xlApp.Quit()

如何准确读取excel文件的代码?TextBox1.Text=worksheet.Cells(2,3).Value我使用了Microsoft excel库。。事实上该整数来自excel文件本身,但它以时间格式显示整数。。多么奇怪的XD现在我想知道如何将这个整数转换成时间格式。我编辑了我的答案,它是从Eldar answers修改而来的。过来看。