shahjagat
asked on
Read .xlsx file
I'm trying to read .xlsx file and populate a DataTable.
I've added test.xlsx file to the project.
Error: The Microsoft Office Access database engine could not find the object 'Sheet1'. Make sure the object exists and that you spell its name and the path name correctly.
<connectionStrings>
<add name="xlsx" connectionString="Provider =Microsoft .ACE.OLEDB .12.0;Data Source=test.xlsx;Extended Properties=Excel 12.0"/>
</connectionStrings>
Private xlsx As String = ConfigurationManager.Conne ctionStrin gs("xlsx") .Connectio nString
Public Function GetData() as DataTable
Dim dt As New DataTable
Dim oleDbCon As New OleDbConnection(xlsx)
oleDbCon.Open()
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1]", oleDbCon)
Dim oleda As OleDbDataAdapter = New OleDbDataAdapter(cmd)
oleda.Fill(dt)
oleDbCon.Close()
return dt
End Sub
Any help would be greatly appreciated!!
I've added test.xlsx file to the project.
Error: The Microsoft Office Access database engine could not find the object 'Sheet1'. Make sure the object exists and that you spell its name and the path name correctly.
<connectionStrings>
<add name="xlsx" connectionString="Provider
</connectionStrings>
Private xlsx As String = ConfigurationManager.Conne
Public Function GetData() as DataTable
Dim dt As New DataTable
Dim oleDbCon As New OleDbConnection(xlsx)
oleDbCon.Open()
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1]", oleDbCon)
Dim oleda As OleDbDataAdapter = New OleDbDataAdapter(cmd)
oleda.Fill(dt)
oleDbCon.Close()
return dt
End Sub
Any help would be greatly appreciated!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I prefer to use tools such as http://www.aspose.com/categories/.net-components/aspose.cells-for-.net/default.aspx to manipulate Excel files
Open in new window