I am trying to import data from excel to mvc
public void DownloadAsExcelOrderReports()
{
try
{
var list = _reportWork.GetList();
GridView gv = new GridView();
gv.DataSource = list;
gv.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.ContentEncoding = System.Text.Encoding.UTF32;
Response.AddHeader("content-disposition", "attachment; filename=Marklist.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
gv.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
}
catch (Exception ex)
{
}
}
This is the code I found online.I get an output like this.
Normally it has to fill in the table itself automatically into excel.I can't see, what i missed.