我想获取单元格中显示的数据(例如AA2 00:43.6
),而不是12:00:44 AM
上面写的值。
如何在没有任何API等的情况下设法这样做
从我的excel 2010示例中查看此图像以获取更多信息:
这是我导入excel文件的代码
MyConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & _
path & "';Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";")
'i also tried IMEX=0
dtTimes = New DataTable
Dim sqlstrTimes As String = "SELECT [RACETIME] " & "FROM [SheetH$];"
'SheetF$
Try
Dim MyCommandHistory As New OleDb.OleDbDataAdapter(sqlstrTimes , MyConnection)
MyCommandHistory.Fill(dtTimes )
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK
, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Finally
MyConnection.Close()
End Try
我查看了connectionstrings.com网站的excel-2010,但没有运气。
答案 0 :(得分:0)
你可以这样试试:
HDR=NO
)的excel文件。将从F1
到Fn
。DataTable
DataTable
删除第一行,因为它实际上是excel中的列标题名称这样你就可以从excel获得文本而不是DateTime值。据我所知,因为excel决定了第一行的数据类型。因此,对于这个hack,第一行是文本(标题),因此决定该列是text / string类型。
MyConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & _
path & "';Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"";")
dtTimes = New DataTable
Dim sqlstrTimes As String = "SELECT [F1] " & "FROM [SheetH$];"
Try
Dim MyCommandHistory As New OleDb.OleDbDataAdapter(sqlstrTimes , MyConnection)
MyCommandHistory.Fill(dtTimes)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK
, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Finally
MyConnection.Close()
End Try
dtTimes.Rows[0].Delete()