使用 OleDbDataAdapter 从 excel 中读取一些采用科学计数法的数字单元格。只有只有数字的字符串(有些可能包含字母)并且是 6 位或 7 位或更多位。我不可能在每个单元格前加上一个 '。在较新版本的 excel 中完全没有问题。旧版本出现问题(我认为是 2003 年,但我不确定)
Dim dt As DataTable = dbConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim dbAdapter As New OleDbDataAdapter("SELECT * FROM [" & strSheet & "] ", dbConn)
我已经尝试了一切,我不知道该怎么做。我尝试按名称选择每一列并连接一个空字符串,我尝试将 IMEX=1 添加到连接字符串中。或修改注册表:
Private Function CheckRegKey() As Boolean
Try
Dim strRows As String = My.Computer.Registry.GetValue( _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel", "TypeGuessRows", "99").ToString
Dim strTypes As String = My.Computer.Registry.GetValue( _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel", "ImportMixedTypes", "zip").ToString
If strRows <> "0" Then
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel", "TypeGuessRows", 0, Microsoft.Win32.RegistryValueKind.DWord)
End If
If strTypes <> "Text" Then
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel", "ImportMixedTypes", "Text")
End If
Catch ex As Exception
Return False
End Try
Return True
End Function
Dim dbAdapter As New OleDbDataAdapter("SELECT * FROM [" & strSheet & "] ", dbConn)
有人有想法么?