使用linq和gridview导出excel的列中包含空格的别名

时间:2013-10-09 17:25:10

标签: linq excel asp.net-mvc-4 gridview alias

我需要导出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?

0 个答案:

没有答案