导出到excel生成零(0)字节文件

时间:2012-10-01 17:30:04

标签: c# asp.net export-to-excel

我编写了一个将网格数据导出到excel的函数。当网格有大约1600行时,导出函数生成0byte文件。但是当行数较少时,它可以正常工作。我的导出代码如下。我没有得到如何/调试的内容!这是因为Response流大小?有人可以告诉我一个方法,如何处理这个问题。

       Response.Clear();
       Response.AddHeader("content-disposition", "attachment; filename=" + "FileName" + ".xls");
       Response.Charset = "";          
       Response.Cache.SetCacheability(HttpCacheability.NoCache);
       Response.ContentType = "application/vnd.xls";
       System.IO.StringWriter stringWrite = new System.IO.StringWriter();
       System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
       grdMain.RenderControl(htmlWrite);

       Response.Write(stringWrite.ToString());
       Response.End();

1 个答案:

答案 0 :(得分:0)

试试这个:

Response.Write(stringWrite.ToString());
Response.Flush();
Response.End();