I want to export html table(not grid) to excel from my content page.I know how to export grid to excel.Same way or diffrent?
Asked
Active
Viewed 800 times
-1
-
you can use excel libraray, download it from codeplex. – Waqar Janjua Jul 12 '12 at 05:35
-
http://stackoverflow.com/questions/9364107/export-html-table-to-excel-using-asp-net – Arun Jain Jul 12 '12 at 05:36
-
If you just need to export "simple data", I would recommend [Excel-friendly] CSV and not the various HTML [hacks] floating about .. it works well here. – Jul 12 '12 at 05:38
-
We expect you to have attempted to solve this problem by yourself rather than asking the community to arrive at a complete solution for you. When you've got some code to show us that demonstrates some effort by you (even if it's wrong) please update your question and flag to re-open. Thanks. – Kev Jul 12 '12 at 11:49
-
@Kev,if u see properly,I already shared my code. – Jui Test Jul 13 '12 at 05:09
1 Answers
2
Try using following code this will help you:
private void ExportToExcel(string strFileName,Table dg)
{
Response.Clear();
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
Response.ClearHeaders();
Response.AddHeader("content-disposition", "attachment;filename=" + strFileName + ".xls");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}