【发布时间】:2014-11-11 21:10:32
【问题描述】:
如果有人能帮助我了解如何在从 gridview 导出数据时启用 Excel 上的筛选功能,我将不胜感激。(Excel 自动筛选)
public ActionResult ExportToExcel(List<EventViewModel> list)
{
try
{
// Main
GridView gv = new GridView();
gv.DataSource = list.ToList();
gv.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.Charset = "";
Response.AddHeader("content-disposition", "attachment; filename=filename.xls");//Response.AddHeader("content-disposition", "inline; filename=Excel.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
return RedirectToAction("Index");
}
catch (System.Exception e)
{
return View("Error");
}
}
【问题讨论】:
-
Hanouf D在谷歌搜索框C# exporting the data from gridview.( Excel Autofilter) 中准确输入以下内容会得到什么? -
他们都使用 autofilter='all' 从视图或 Microsoft.Office.Interop.Excel 库与 asp.net 网页。但我正在使用 ASP.NET MVC 4 - 剃刀视图>
标签: c# asp.net-mvc gridview export-to-excel