导出到excel在本地但不在服务器上工作

时间:2014-02-19 13:20:06

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

我知道在很多论坛上都会多次询问这类问题,但这个问题让这个问题变得陌生,它在本地服务器和服务器上都有一个模块,但不适用于另一个模块。

让我更清楚。

我正在为一个模块导出excel表,比如使用以下代码

   public void ExportToExcel(string fileName, GridView gv)
     {  
        try
        {
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", fileName));
        HttpContext.Current.Response.ContentType = "application/excel";
        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        gv.RenderControl(htw);
        HttpContext.Current.Response.Write(sw.ToString());
        HttpContext.Current.Response.End();
        }
        catch (Exception ex)
        {
        }        
    }

并导出另一个列表,说零售商使用相同的代码。我在本地和第二个模块上调试它给出了异常

ThreadAbortException但只有一个记录列表。

按照建议here我使用了HttpContext.Current.ApplicationInstance.CompleteRequest但是得到了意想不到的结果(整个页面已经过期)

0 个答案:

没有答案