Make excehsheet from HTML in ASP.net C#

protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "application/x-msexcel";
        Response.AddHeader("Content-Disposition", "attachment;filename=HTML_TO_Excel.xls");
        Response.ContentEncoding = Encoding.UTF8;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        tblExcel.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }

Use Namespace

using System.Text;
using System.IO;

In HTML, use the tag runat="server" and assign ID to table tag eg.

<table border="1" runat="server" id="tblExcel">

 

 

 

 

 

Related Alrticles

FREE!!! Registration