16,721
社区成员




"Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + Server.MapPath(filenameurl) + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'"
处理excel07、10连接字符串两点不同:"Provider=Microsoft.ACE.OLEDB.12.0;" + "data source=" + Server.MapPath(filenameurl) + ";Extended Properties='Excel 12.0 Xml; HDR=YES; IMEX=1'"
Private Function get_excel(fileName As String) As Data.DataSet
Dim strCon As String
Dim myConn As OleDb.OleDbConnection
Dim myDataSet As Data.DataSet = New Data.DataSet
strCon = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source ='" + fileName + "';Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"
'HDR=YES(有标题行,读取时第一行忽略);
'HDR=NO(无标题行,从第一行开始读取);
'Excel 8.0; Excel的版本
myConn = New System.Data.OleDb.OleDbConnection(strCon)
Dim strComMain As String = " SELECT * FROM [Sheet1$]"
myConn.Open()
Dim myCommandMain As New System.Data.OleDb.OleDbDataAdapter(strComMain, myConn)
myDataSet = New DataSet
Try
myCommandMain.Fill(myDataSet)
Catch ex As Exception
MsgBox(ex.Message)
Finally
myConn.Close()
End Try
get_excel = myDataSet
End Function
下次你最好贴完整代码可以直接调试,测试的,或是上传Demo。没办法调试你的,我网上找了一段,测试后确认有效。你可以试试。
只可以xls