Export BO to Excel


Author
Message
Juan Carlos Pazos
Juan Carlos Pazos
StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)
Group: Forum Members
Posts: 144, Visits: 227
Hi

I use many times information from SF forums and many times when I had some question, someone help me a lot; so I think in contribute a routine that can you use in your applications. Hope someone benefit from this small sample.

The sample shows how to use the information in a ListView and export that information to MS Excel, I use the StrataFrame Sample database taking information from Orders and Order_Items to make a simple list, I fill that in the form and click the button it will check if it's installed Excel, if it's installed will lunch Excel, create header, subheaders and column headers with some format, then it will pass all the data of the BO filling one by one the rows in Excel, also it groups the information (I did this for the order number but you can make it to any thing you need) also add a row for subtotal for every group and at the end a grand total for all. Also sas a small formating the Excel sheet routine.

You have this:

And you will get this:

I hope you find usefull; and if someone has a way to Import from Excel to a BO it will be great because thats the next thing I need to doWink

Regards

Smile Everything is possible, just keep trying...

Attachments
ExportExcel.zip (406 views, 163.00 KB)
Reply
Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K 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...




Threaded View
Threaded View
Juan Carlos Pazos - 16 Years Ago
Edhy Rijo - 16 Years Ago
Greg McGuffey - 16 Years Ago
Teddy Jensen - 16 Years Ago
Juan Carlos Pazos - 16 Years Ago
                 Thanks for the contribution, Juan!
Trent L. Taylor - 16 Years Ago
Paul Chase - 16 Years Ago
                         Awesome example Paul!
Greg McGuffey - 16 Years Ago
                             Paul Thanks for the idea, I want to try and add a sample of this (or...
Juan Carlos Pazos - 16 Years Ago
                                 Hi Juan, That functionwouldcall a form with a drop down that is bound...
Paul Chase - 16 Years Ago
Keith Chisarik - 16 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search