Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > export data
 

export data

How can I export data from a Datagrid to an Excel file?

I know how to do in ASP.NET, but I want to do the same operation in a WindowsForm application.

Thanks in advance
MigrationUser 1  Tuesday, July 01, 2003 6:29 AM
Nobody knows...?
MigrationUser 1  Wednesday, July 02, 2003 3:41 AM
how do you do it in ASP.NET and maybe we can help you figure it out in WindowsForms?  Using OleDb or screen scraping or what?
MigrationUser 1  Wednesday, July 02, 2003 4:26 AM
Something like this... I think that in WindowsForm is totally different --->

Response.ContentType = "application/vnd.ms-excel" 
Response.AddHeader("Content-Disposition", "filename=Report.xls;") 
Response.Charset = "" 
Response.Buffer = False 
Me.EnableViewState = False 

Dim tw As New System.IO.StringWriter() 
Dim hw As New System.Web.UI.HtmlTextWriter(tw) 

' tell the grid to render itself into the html text writer 
grdReport.RenderControl(hw) 

Dim strHtml As String = tw.ToString 
Dim iLoop As Int32 
Dim Multiple As Int32 = Fix(strHtml.Length / 1000) 

' now write the contents of the html string to the client 
For iLoop = 0 To Multiple 
Response.Write(Mid(strHtml, (100000 * iLoop) + 1, 100000)) 
Response.Flush() 
Next 

Response.End()
MigrationUser 1  Wednesday, July 02, 2003 5:13 AM
Yah, that definitely won't work in WindowsForms, um...I'm not sure how you would do that honestly...maybe someone else will know.

I do know that you can use OleDb to open up an Excel file and read data like it's a DataTable.  I'm wondering though if you can use it to go the other way.  Might want to play around with that.
MigrationUser 1  Wednesday, July 02, 2003 2:01 PM
You could probably use the MS Primary Interop Assemblies to interact with Excel.  If you can pull out data as XML and then stream it in, you might be good to go...
MigrationUser 1  Wednesday, July 02, 2003 3:10 PM
Hey Jacob, can you post a link to those?
MigrationUser 1  Wednesday, July 02, 2003 3:13 PM
Sure, you can get them <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c41bd61e-3060-4f71-a6b4-01feba508e52&DisplayLang=en">here</a>.
MigrationUser 1  Wednesday, July 02, 2003 3:15 PM

You can use google to search for other answers

Custom Search

More Threads

• Connecting SQLConnection with DataGridView
• DataGridView, CurrencyManager
• ADO.NET - Working with 'Date type' - Is this a bug?
• simple question about DataGridView
• Display error in datagridview bound to collection
• Calculate column in DataGridView
• Auto sum up value in datagridview
• DataGridView (How do I databind a column's combobox to and enum?)
• capture the Keyup & KeyDown in a Datagrid
• pagination in windows forms?