Ich versuche, eine Tabellenkalkulationsdatei Book1.xls
genannt zu lesen, die ein Arbeitsblatt Sheet1
Allerdings erhalte ich die folgende Fehlermeldung genannt enthält:
The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.
Hier ist ein Ausschnitt aus dem Code ich verwende:
Dim dt As DataTable = New DataTable()
Select Case fileExt
Case ".csv"
Dim reader As New CsvReader
dt = reader.GetDataTable(filePath)
Case ".xls", ".xlsx"
Dim oleDbConnStr As String
Select Case fileExt
Case ".xls"
oleDbConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2"""
Case ".xlsx"
oleDbConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & filePath & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2"""
End Select
Using oleDbConn As OleDbConnection = New OleDbConnection(oleDbConnStr)
oleDbConn.Open()
Dim oleDbCmd As New OleDbCommand("SELECT * FROM [Sheet1$]", oleDbConn)
Dim oleDbDa As New OleDbDataAdapter(oleDbCmd)
oleDbDa.Fill(dt)
oleDbConn.Close()
End Using
End Select
ich kann nicht verstehen, warum der Code nicht mein Arbeitsblatt finden können. Warum ist das und wie kann ich es lösen?
versuchen Sie es einmal mit absolutem Pfad: Datenquelle = C: \\ myexcel.xls; –
@AshwiniVerma 'Dateipfad' ist der absolute Pfad, weil ich 'Server.MapPath()' – Curt
diesen Link benutze und versuche, Blattname durch Programmierung zu bekommen: http://forums.asp.net/t/1751143.aspx/1 –