R
Roger Twomey
I have an app that reads excel spreadsheets. It works fine, as long as the
first sheet is called "Sheet1". If there is no sheet called Sheet1 it
crashes.
I don't want to force the user to change the spreadsheet, I want to read the
first page no matter what it is called.
Here is how my code works right now:
<code>
Dim myds As New DataSet
Dim MyExcelConnectStr As String = "Provider=Microsoft.Jet.OLEDb.4.0;data
source=" & strFileName & ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""
strExcelSQL = "SELECT * FROM [Sheet1$]"
Dim MyOleADapter As New OleDb.OleDbDataAdapter(strExcelSQL,
MyExcelConnectStr)
MyOleADapter.Fill(myds, "xlsdata")
intRows = myds.Tables(0).Rows.Count
intFields = myds.Tables(0).Columns.Count
</code>
Is there some function or code that can be used in place of:
strExcelSQL = "SELECT * FROM [Sheet1$]"
which will provide the same function (open sheet1) without knowing it's
name? (which may not be Sheet1). Or, a way to GET the first sheets name
(vb.net)?
Thanks.
first sheet is called "Sheet1". If there is no sheet called Sheet1 it
crashes.
I don't want to force the user to change the spreadsheet, I want to read the
first page no matter what it is called.
Here is how my code works right now:
<code>
Dim myds As New DataSet
Dim MyExcelConnectStr As String = "Provider=Microsoft.Jet.OLEDb.4.0;data
source=" & strFileName & ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""
strExcelSQL = "SELECT * FROM [Sheet1$]"
Dim MyOleADapter As New OleDb.OleDbDataAdapter(strExcelSQL,
MyExcelConnectStr)
MyOleADapter.Fill(myds, "xlsdata")
intRows = myds.Tables(0).Rows.Count
intFields = myds.Tables(0).Columns.Count
</code>
Is there some function or code that can be used in place of:
strExcelSQL = "SELECT * FROM [Sheet1$]"
which will provide the same function (open sheet1) without knowing it's
name? (which may not be Sheet1). Or, a way to GET the first sheets name
(vb.net)?
Thanks.