Posted to microsoft.public.dotnet.languages.vb,microsoft.public.excel.programming
|
|
Refer to sheet2 - even when named
Masa, could you repost paying attention to line break. TIA
Greg
Masa Ito wrote:
"Charlie Brown" wrote in
oups.com:
This may be helpful to you. Query the spreadsheet and return the name
property of the indexed sheet you would like to use.
http://weblogs.asp.net/donxml/archiv.../21/24908.aspx
Thank you - this worked perfectly.
fwiw I ended up creating the following function:
Public Shared Function GetExcelSheetNames(ByVal fiExcel As FileInfo) As
ArrayList
Dim arl As New ArrayList
Dim sConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & fiExcel.FullName & _
";Extended Properties=""Excel 8.0;HDR=Yes"""
Dim cn As New OleDbConnection(sConn)
Dim dt As New DataTable
cn.Open()
dt = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object()
{Nothing, Nothing, Nothing, "Table"})
cn.Close()
For Each r As DataRow In dt.Rows
If dt.Columns.Contains("TABLE_NAME") Then
arl.Add(r("TABLE_NAME"))
End If
Next
Return arl
End Function
For anyone googling and finding this, note that the sheet names end with
$, seems the last 'TABLE' is the file name. ie: excel file named MyFile
with two sheets named: Sheet1, MySheet will return 3 strings in this
arraylist - Sheet1$, MySheet$, MyFile
|