我試圖從MVC 4中使用Gridview將表格從數據庫導出到Excel。任何人都可以告訴我如何爲excel表格中的導出行賦予顏色?導出要格式化
public ActionResult ExportToExcel()
{
GridView gv = new GridView();
gv.DataSource = db.StudentRecords.ToList();
gv.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=Marklist.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");
}
請考慮這個優秀的組件:http://epplus.codeplex.com/ –