我需要导出Excel并且我正在使用MVC4
这是我的代码
var co = from c in context.AN_COMPANY
orderby c.COMPANY_DESCR
select c;
List<AN_COMPANY_EXT> societa_list = new List<AN_COMPANY_EXT>();
foreach (var o in co)
{
AN_COMPANY_EXT c_ex = new AN_COMPANY_EXT(o);
societa_list.Add(c_ex);
}
GridView gv = new GridView();
gv.DataSource = (from d in societa_list
select new { Codice = d.ID_COMPANY, Descrizione = d.COMPANY_DESCR, SAP_Alias = d.COMPANY_SAP_ALIAS, Booking_Company = d.IS_BOOKING_COMPANY });
gv.DataBind();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=AnagraficaSocieta.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
return RedirectToAction("Index");
如何使用空格设置列名称,例如“SAP ALIAS”而不是SAP_ALIAS?