Export data to Excel

G

Grey

is it possible to export excel directly from ASP.NET to Excel? My requirement is that the data on the datagrid is exported to MS Excel file after user clicks the button on the web page. Excel will be open automatically with imported data. If so, is need to add any additional controls or tools?


Million Thanks..

Eric Yum
 
G

Glenn

There is a third party tool called ExcelWriter that allows
you to easily create spreadsheets without having Excel
installed on the server. It is very quick and easy to
use... check it out at www.softartisans.com.

It is a COM component but they have class wrappers that
allow you to use it in .NET. The latest version lets you
create spreadsheet content by binding a DataSet (previous
versions only support ADO recordset binding - you have to
create the rows manually).

Cheers,

Glenn.
-----Original Message-----
is it possible to export excel directly from ASP.NET to
Excel? My requirement is that the data on the datagrid is
exported to MS Excel file after user clicks the button on
the web page. Excel will be open automatically with
imported data. If so, is need to add any additional
controls or tools?
 
S

Steve C. Orr [MVP, MCSD]

This article gives a number of possible solutions:
http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp

And here's another technique that might work for you:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q306572

And these 3rd party components are of high quality:
http://www.aspose.com/Products/Aspose.Excel/
http://officewriter.softartisans.com/

I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



is it possible to export excel directly from ASP.NET to Excel? My requirement is that the data on the datagrid is exported to MS Excel file after user clicks the button on the web page. Excel will be open automatically with imported data. If so, is need to add any additional controls or tools?


Million Thanks..

Eric Yum
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top