"Syd" wrote:
Hi all,
Is there a way to get data from a datagrid and send to an excel table?And if
it is possible how can arranged the excel table...
Thanks
Exporting data to Excel file is pretty simple. You just need to add few
headers. The DataGrid can be saved and opened with MS Excel or you can
directly open it in the browser as per your requirement.
<CODE>
Response.Clear();
// Content-disposition causes force download
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
</CODE>
Find more information at:
http://www.codeproject.com/aspnet/DA...ortToExcel.asp
Hope it will help.
--
Cheers,
Rahul Anand