0
I have a list and would like to export to Excel, in this code this bringing the records correctly, just do not export the file.
I need to add something else or I’d have another way?
CorpDAO dao = new CorpDAO();
List<CorpCRM> listaExport = dao.ListarCorp(produto, anomes, nome, matricula, pernumber);
var listCarregaExcel = listaExport;
DataGrid rptExcel = new DataGrid();
rptExcel.DataSource = listCarregaExcel;
rptExcel.DataBind();
Response.Clear();
Response.Buffer = true;
Response.ContentEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=Relatório_lista.xls");
Response.Charset = "";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
rptExcel.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
rptExcel = null;
listCarregaExcel = null;
Response.End();
what’s going wrong? what’s the error message?
– Ricardo Pontual