Private Sub ExportToExcel(ByVal strFileName As String, ByVal dg As GridView)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim oStringWriter As New System.IO.StringWriter
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
GridView1.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.[End]()
End Sub
Ypu code is to export data from gridview to excel. I need code to export data from other controls too. For example I have Item Number, Revision and Description values as Labels. How can I get these values to excel?
you can construct HTML out of the data which you want to render to excel and then set the same on Response object and send it to client...it will work...
mnmhemaj
Member
200 Points
178 Posts
Data from VB.net to Excel
May 07, 2012 10:09 AM|LINK
Hi
I need to export both gridview data and data from other textbox and label controls in vb.net form to Excel.
I can export data from Gridview. But I don't know how to send other data simultaneously.
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Data from VB.net to Excel
May 07, 2012 10:18 AM|LINK
Private Sub ExportToExcel(ByVal strFileName As String, ByVal dg As GridView) Response.Clear() Response.Buffer = True Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Me.EnableViewState = False Dim oStringWriter As New System.IO.StringWriter Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter) GridView1.RenderControl(oHtmlTextWriter) Response.Write(oStringWriter.ToString()) Response.[End]() End SubMCP
mnmhemaj
Member
200 Points
178 Posts
Re: Data from VB.net to Excel
May 07, 2012 10:38 AM|LINK
Hi
Ypu code is to export data from gridview to excel. I need code to export data from other controls too. For example I have Item Number, Revision and Description values as Labels. How can I get these values to excel?
ramiramilu
All-Star
97829 Points
14494 Posts
Re: Data from VB.net to Excel
May 07, 2012 11:30 AM|LINK
you can construct HTML out of the data which you want to render to excel and then set the same on Response object and send it to client...it will work...
Thanks,
JumpStart
mnmhemaj
Member
200 Points
178 Posts
Re: Data from VB.net to Excel
May 07, 2012 11:48 AM|LINK
Hi
Can you please explain it in detail or with a small example?
Nasser Malik
Star
12536 Points
1867 Posts
Re: Data from VB.net to Excel
May 07, 2012 06:51 PM|LINK
see .. it's in csharp but you can easily convert to vb
http://blogs.msdn.com/b/erikaehrli/archive/2009/01/30/how-to-export-data-to-excel-from-an-asp-net-application-avoid-the-file-format-differ-prompt.aspx
http://www.codeproject.com/Tips/274204/Export-any-page-to-Excel-automatically
http://www.codeproject.com/Tips/269854/Export-whole-page-to-Excel-with-infragistics-in-as
http://www.codeproject.com/Articles/164582/8-Solutions-to-Export-Data-to-Excel-for-ASP-NET
Skype: maleknasser1