我试图在 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");
}