Hi Rino,
This program will not only open an excel file but it will also read the content of the file.. the sample program i created for you will read data in your excel file and insert it into a dataset.. no need to add COM or any references.
'first specify the path and filename of your excel
Dim PathFilename As String = "C:\TESTME.xls"
'second is specify the sheet name you want to read
Dim strSheetName As String = "Sheet1"
'create a connection
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DS As System.Data.DataSet
Dim _sqlqry As String
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Micros oft.Jet.OLEDB.4.0; " & _
"data source='" & PathFilename & " '; " & "Extended Properties=Excel 8.0;")
'Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [" & strSheetName & "$]", MyConnection)
DS = New System.Data.DataSet
MyCommand.Fill(DS)
MyConnection.Close()
MyConnection.Dispose()
MyConnection = Nothing
================================================== ===
Hi there
I'm fairly new to .net and learning as I go using books and the net. I have some 4 years of VB6 behind me.
I'm writing an app in which I need to import data from a spread sheet.
I have so far wasted several hours trying to work out how to simply open the file.
In the msdn help files I found the code below, problem is it doesn't work..:
Dim wb As Excel.Workbook = _
Application.Workbooks.Open("C:\YourPath\YourWorkbo ok.xls")
I have added excel to my COM references.
I would be very grateful if someone could give me a bit of code to do this very basic thing.
Thanks very much in advance!!
Rino