我在C# asp.net web应用程序中有一些默认功能,可以将网格视图导出为excel文件。这段代码在Excel2007中运行得很好,但是它在2010年不会打开。我需要升级这段代码才能在两者中工作,或者找到新的解决方案。任何帮助都是最好的。
当前代码:
gvReport.Style.Add("font-size", "1em");
Response.Clear();
string attachment = "attachment; filename=FileName.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvReport.GridLines = GridLines.Horizontal;
gvReport.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();发布于 2012-05-08 02:35:41
使用EPPlus并将数据导出到Excel,我假定gvReport使用GridView控件,因此使用绑定到该GridView并使用EPPlus导出数据。
这很简单,你可以在这里找到返回从DataTable创建excel文件的ashx处理程序的例子:
https://stackoverflow.com/questions/10487091
复制相似问题