Howto: Display ASP.NET Results Using Excel in IE ?

  • Thread starter Thread starter Lukman
  • Start date Start date
L

Lukman

Hi,
Do you know how to display ASP.NET result (database result from ADO.NET)
using Excel in IE ?
Thanks,
 
Lukman said:
Do you know how to display ASP.NET result (database result from ADO.NET)
using Excel in IE ?

You need to connect to Excel, generate the XLS (you could short cut with
Excel DB drivers) then stream the XLS to the user with the proper mime type.
 
I have looked high and low for a simple solution to export a DataGrid to MS Excel in ASP.NET. I weeded out this code from Microsoft support. Simply create a button called ExportToExcel and place this code in the Click event and rename DataGrid1 in the code to whatever your datagrid is called. When you run the page and click your button you will be prompted to open excel in ie or save whatever data is in your datagrid to an excel file of your choice. I hope this saves beginner programmers such as myself some time and effort

sub ExportToExcel_Click(sender As Object, e As EventArgs

' Set the content type to Excel
Response.ContentType = "application/vnd.ms-excel
' Remove the charset from the Content-Type header
Response.Charset = "
' Turn off the view state
Me.EnableViewState = Fals

Dim tw As New System.IO.StringWriter(
Dim hw As New System.Web.UI.HtmlTextWriter(tw
' Get the HTML for the control
DataGrid1.RenderControl(hw
' Write the HTML back to the browser
Response.Write(tw.ToString()
' End the response
Response.End(
End I

End Su
 
What's the End If all about? There's no If to start it...

pdm2 said:
I have looked high and low for a simple solution to export a DataGrid to
MS Excel in ASP.NET. I weeded out this code from Microsoft support. Simply
create a button called ExportToExcel and place this code in the Click event
and rename DataGrid1 in the code to whatever your datagrid is called. When
you run the page and click your button you will be prompted to open excel in
ie or save whatever data is in your datagrid to an excel file of your
choice. I hope this saves beginner programmers such as myself some time and
effort.
 
Back
Top