Export BO to Excel


Author
Message
Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
Here is the function I use a lot to get sheet names, this specific example i know I always want the first sheets name, but you can enumerate through all the sheets. I am sure I stole borrowed Smile this from somewhere and adapted it to fit my need, but it works great as I pulled this out of an import screen that I know gets beat on quite a lot. Hope it helps.

''' <summary>

''' This method retrieves the excel sheet names from

''' an excel workbook.

''' </summary>

''' <param name="excelFile">The excel file.</param>

''' <returns>String[]</returns>

Private Function GetExcelSheetNames(ByVal excelFile As String) As String

Dim objConn As OleDbConnection = Nothing

Dim dt As System.Data.DataTable = Nothing

Try

' Connection String. Change the excel file to the file you

' will search.

Dim connString As String = ("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=") + excelFile & ";Extended Properties=Excel 8.0;"

' Create connection object by using the preceding connection string.

objConn = New OleDbConnection(connString)

' Open connection with the database.

objConn.Open()

' Get the data table containg the schema guid.

dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)

If dt Is Nothing Then

Return Nothing

End If

Dim excelSheets As String() = New String(dt.Rows.Count - 1) {}

Dim i As Integer = 0

' Add the sheet name to the string array.

For Each row As DataRow In dt.Rows

excelSheets(i) = row("TABLE_NAME").ToString()

i += 1

Next

' Loop through all of the sheets if you want too...

For j As Integer = 0 To excelSheets.Length - 1

' Query each excel sheet.

Next

' Return excelSheets

Return excelSheets(0)

Catch ex As Exception

Return Nothing

Finally

' Clean up.

If objConn IsNot Nothing Then

objConn.Close()

objConn.Dispose()

End If

If dt IsNot Nothing Then

dt.Dispose()

End If

End Try

End Function



Keith Chisarik
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search