用VB.net导入Excel 2007表文件 外部表不是预期的格式
PrivateSubRead()DimfileNameAsString="D:\\YXZC\YXZC\yxzc.xlsx"DimstrConnAsString="Prov...
Private Sub Read()
Dim fileName As String = "D:\\YXZC\YXZC\yxzc.xlsx"
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & fileName & "';Extended Properties=Excel 8.0;"
Dim objDS As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection
MyConnection = New System.Data.OleDb.OleDbConnection(strConn)
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
objDS = New System.Data.DataSet()
MyCommand.Fill(objDS, "[Sheet1$]")
MyConnection.Close()
End Sub
如上,连接时出现“外部表不是预期的格式”错误。但有意思的是,当把yxzc.xlsx文件打开后运行程序,则无错误,另外,转换成2003以前的版本(.xls)也是正确的。希望高手帮忙解惑。
PS:英雄之城,一个很有意思的游戏,本人打算改进一下排兵软件,期间遇到以上问题。注册网址:http://act.woniu.com/hero/mtgg090424/?sid=47688297 展开
Dim fileName As String = "D:\\YXZC\YXZC\yxzc.xlsx"
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & fileName & "';Extended Properties=Excel 8.0;"
Dim objDS As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection
MyConnection = New System.Data.OleDb.OleDbConnection(strConn)
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
objDS = New System.Data.DataSet()
MyCommand.Fill(objDS, "[Sheet1$]")
MyConnection.Close()
End Sub
如上,连接时出现“外部表不是预期的格式”错误。但有意思的是,当把yxzc.xlsx文件打开后运行程序,则无错误,另外,转换成2003以前的版本(.xls)也是正确的。希望高手帮忙解惑。
PS:英雄之城,一个很有意思的游戏,本人打算改进一下排兵软件,期间遇到以上问题。注册网址:http://act.woniu.com/hero/mtgg090424/?sid=47688297 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询