每行使用response.flush时无法下载excel

时间:2016-10-31 15:10:46

标签: asp-classic out-of-memory buffer response

(它是一个原始代码,它适用于大约10000行)

fileName = excelTemplate+".xls"
Response.Write "<html><body><table>"
For Loop for more then 150000 Rows 
{
    Response.Write "<tr><td>..........</td></tr>"
}
Response.Write "</table></body></html>"
Response.AddHeader "content-disposition", "attachment; filename=""" & fileName & ""
Response.Charset = "UTF-8"
Response.ContentType = "application/vnd.ms-excel"           
Response.Flush  

我收到缓冲区大小错误(执行ASP页面导致响应缓冲区超出其配置的限制。)

我在循环中尝试了Response.Flush:

For Loop for more then 150000 Rows 
{
    Response.Write "<tr><td>..........</td></tr>"
    Response.Flush
}

现在我没有收到大小限制问题但无法下载excel ..(所有输出都在网页上呈现)

在浏览了一些博客后,我发现此问题的另一个解决方法是增加IIS的缓冲区大小,但只是想知道是否有其他替代此问题的方法..

1 个答案:

答案 0 :(得分:0)

您需要移动Response.ContentType,Response.Charset&amp;第一个Response.Write

之前的Response.AddHeader
<%
    Response.Buffer = True
    ...
    fileName = excelTemplate+".xls"
    Response.AddHeader "content-disposition", "attachment; filename=""" & fileName & ""
    Response.Charset = "UTF-8"
    Response.ContentType = "application/vnd.ms-excel"           
    Response.Write "<html><body><table>"
    For Loop for more then 150000 Rows 
    {
        Response.Write "<tr><td>..........</td></tr>"
        Response.Flush
    }
    Response.Write "</table></body></html>"
    Response.Flush  
%>