I download an Excel 2003 formated XLS file form a web page (No choice on formatting) and need to extract the data. I should be able to read the contents as a database without the need to open it first but it won't let me read it without opening it first!
Since its a 2003 xls file if I do open it it gives a warning that it might be corrupt blah blah and I need to confirm the opening of the file! Then I click on my read data and it shows it fine in my datagridview!
Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.Office.Interop.Excel
Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim dataSet As System.Data.DataSet
Dim datareader As OleDbDataReader
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim path As String = "C:\holding\list_demands.xls"
MyConnection = New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.ace.OLEDB.12.0;Data
Source=" + path + ";Excel 8.0 XML;HDR=YES;Format=xls")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from
[List_demands$]", MyConnection)
MyConnection.Open()
dataSet = New System.Data.DataSet
MyCommand.Fill(dataSet)
DataGridView1.DataSource = dataSet.Tables(0)
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try