Export data into Excel, Word and PDF with Formatting
<p>I want to export data of DataTable or DataSet with formating like Color of Header-Footer, Font Size, Row Color in Word, Excel and PDF format. Is it possible?</p>

<p>If yes then how? Please healp me.
My code is as below.</p>

<pre><code>public void ExportToExcel(DataTable dt)
{   
        con.Open();
        string sql = "select *from test";
        cmd = new SqlCommand(sql, con);
        dt = new DataTable();
        da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        cmd.Dispose();

        string filename = "DownloadTest.xls";
        System.IO.StringWriter tw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
        DataGrid dgGrid = new DataGrid();
        dgGrid.DataSource = dt;
        dgGrid.DataBind();
        DataSet ds = new DataSet();
        ds = dt.Clone;

        dgGrid.RenderControl(hw);

        Response.ContentType = "application/vnd.ms-excel";
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
        this.EnableViewState = false;
        Response.Write(tw.ToString());
        Response.End();


        con.Close();
}
</code></pre>
