1

I am dumping the data from a table to an excel sheet which is created during run time.I have the file path in Session["Fullpath"]. I am able to create the excel with contains the data of table1.Now, I have one more table table2.I want to dump the data from table table2 to the second sheet of the same excel.

Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename= " + Session["Fullpath"]);
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
table.RenderControl(htw);
Response.Output.Write(sw.ToString());
System.IO.File.WriteAllText(Session["Fullpath"].ToString(), sw.ToString());
Response.Flush();
Response.End();
tereško
  • 58,060
  • 25
  • 98
  • 150
Joy
  • 21
  • 1
  • 5
  • You might want to have a look at this http://stackoverflow.com/questions/7632782/export-gridview-to-multiple-excel-sheet – Jonas T Feb 11 '14 at 05:59
  • Use some library like EPPLUS - it has a method FromDataTable(), which creates a xlsx in millseconds. Plus it has full support for the xlsx file format, e.g. additional sheets etc. – Christian Sauer Feb 11 '14 at 07:13

0 Answers0