1
I need to generate separate excel files. I tried to do in a foreach
foreach (var item in listExtracts)
{
DataTable table = Mytable;
var grid = new GridView { DataSource = table };
grid.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=ArquivoExcelPessoas.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
But the following error appears...
I tried other methods, in all at first it generates the file, but in the loop it gives the error.
Am I doing something wrong or is there another way to do it?