22 Mart 2010 Pazartesi

Excel'e export etme için kullanıabilecek kod parçası

//Excell dosyası oluşturmak için kullanabileceğimiz kod parçası...

DataTable dtList = //Databaseden ilgili data çekilir....

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

Response.ContentEncoding = System.Text.ASCIIEncoding.Default;

Response.AddHeader("Content-Disposition", "inline;filename=LISTE.xls");

//DataGrid nesnesi oluşturup DB'den gelen liste bu grid'e bind edilir...

grdReport.DataSource = dtList;

grdReport.DataBind();

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

grdReport.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();

Hiç yorum yok:

Yorum Gönder