How to export datagrid to excel,note pad,PDF using Asp.Net?
By in ASP.NET on Oct 30 2006
  • sumanth praveen
    Nov, 2006 3

    you can export datagrid to word,excel using httpresponce object and string builder/string.

    here is the following code to expost datagrid to word.

    u can change type to .xls from .doc to export to excel.

    i tried to export to pdt, but it didn't works fine.

    -----------

    Response.Clear();

    Response.AddHeader("content-disposition", "attachment;filename=Yearwise Yield and Expenses.doc");

    Response.Charset = "";

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    Response.ContentType = "application/vnd.word";

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

    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

    DataGrid1.ForeColor=Color.Black;

    DataGrid1.HeaderStyle.BackColor=Color.White;

    DataGrid1.HeaderStyle.Font.Bold=true;

    DataGrid1.HeaderStyle.Font.Size=11;

    DataGrid1.ItemStyle.ForeColor=Color.Black;

    DataGrid1.ItemStyle.Font.Size=11;

    DataGrid1.ItemStyle.VerticalAlign=System.Web.UI.WebControls.VerticalAlign.Top;

    DataGrid1.ItemStyle.HorizontalAlign=System.Web.UI.WebControls.HorizontalAlign.Left;

    Table1 .Font.Size=9;

    Table1.BorderWidth=0;

    Table1.RenderControl(htmlWrite);

    htmlWrite.WriteLine("

    ");

    DataGrid1.RenderControl(htmlWrite);

    htmlWrite.WriteLine("

    ");

    Response.Write(stringWrite.ToString());

    Response.End();

    -------------

    siply copy this code it will work fine

    • 0
  • Oct, 2006 30

    How to export datagrid to excel,note pad,PDF using Asp.Net?

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS