I have an html table (Not Gridview) and that has no proper Header and rows. Instead it has customized structure and data. I want to export this table to Excel. How can I do using ASP.NET?
The labels are fixed text and the integer values are coming from database. So the table structure is fixed only the integer/decimal values change.
You want Export HTML table (Not Gridview) customized structure and data to Excel using ASP.NET.
Try the following Approach
Provide the ID
and add runat="server"
attribute
<table id="tbl" runat="server" >
Add the following code
Response.ContentType = "application/x-msexcel";
Response.AddHeader("Content-Disposition", "attachment;
filename=ExcelFile.xls");
Response.ContentEncoding = Encoding.UTF8;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
tbl.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();