export to excel functionalities

Posted: March 4, 2005 in Uncategorized

Often it needed in many application to export to excel from grid,datset/recordset .there are few approacjes regd the same the primitives are use of scripting object’s create object ,use of excel object library com object,use of the excel driver object and the render objects.

however if you are in web apps and you need the same from datgrid to excel and u didn’t ahve any control in datagrid then then the siomple rendering like is very fast and useful


void ExportDataGridDataToExcel(DataGrid dg)


Response.ContentType = "application/vnd.ms-excel";

// Remove the charset from the Content-Type header.

Response.Charset = "";

// Turn off the view state.

this.EnableViewState = false;

System.IO.StringWriter tw =

new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter hw =

new System.Web.UI.HtmlTextWriter(tw);

// Get the HTML for the control.


// Write the HTML back to the browser.


// End the response.



for datagrid with control u need to implement some div tag and table rendering as well.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s