日期:2014-05-17  浏览次数:20892 次

关闭缓冲后程序出错
这一段程序是将数据导出到EXCEL表中,由于导出的数据太大,所以需要将缓冲关闭,但是我关闭缓冲后就程序出错:
错误信息是:
Response   对象   错误   'ASP   0156   :   80004005 '  

HTTP   头错误  

/erp/Stock/StockToExcel.asp,行   71  

已将   HTTP   头输出到客户端浏览器。任何对   HTTP   头的修改都必须在输出页内容之前进行。

程序错在这四行:
Response.Buffer=True
Response.ContentType= "application/X-msdownload "
Response.Redirect( "report/ "   &   Request.ServerVariables( "REMOTE_ADDR ")   &   ".xls ")

源程序如下:
<%
//-----输出的数据量可能会很大导致出错,将缓冲关闭即可-----//
Response.Buffer   =   False
//-----设置ASP脚本超时为1500秒-----//
Server.ScriptTimeout   =   1500
%>
<!--#include   file= "../../UserOnLine.asp "-->
<!--#include   file= "../Conndb.asp "-->
<!--#include   file= "../Functions.asp "-->
<title> 导出结果到Excel表格 </title>
<%
//===赋值为空格,防止在写入不到数据库的首行记录===//
NumGZWH2   =   " "
NumP001   =   " "
NumQ001   =   " "
NumQ002   =   " "
NumQ003   =   " "
StrCustName   =   " "
//===保存文件名IP.xls到服务器本目录的report文件夹===//
Set   Fs   =   Server.CreateObject( "scripting.filesystemobject ")
FileName   =   Server.MapPath( ". ")   &   "\report\ "   &   Request.ServerVariables( "REMOTE_ADDR ")   &   ".xls "

//===文件已存在的话先删除文件===//
if   Fs.FileExists(FileName)   then
Fs.DeleteFile(FileName)
end   if    
set   MyFile   =   Fs.CreateTextFile(FileName,true)
//===打开数据库===//
Set   Rs   =   Server.CreateObject( "ADODB.RecordSet ")
Sql   =   "SELECT   DES2   As   客户货号,   DES   As   货品名称,   ITEM_CODE   As   货品编号   "   _
    + "FROM   UN_ITEM1   WHERE   "   &   Session( "CurrentFields ")   &   "   Like   ' "   &   Session( "CustCode ")   &   "% ' "        
Rs.Open   Sql,conn,1,1

if   Rs.RecordCount> 0   then    
//===写标题===//
strLine= " "
strLine   =   strLine   &   "客户货号 "   &   chr(9)
strLine   =   strLine   &   "货品名称 "   &   chr(9)
strLine   =   strLine   &   "成品仓 "   &   chr(9)
strLine   =   strLine   &   "包装部 "   &   chr(9)
strLine   =   strLine   &   "退货待处理 "   &   chr(9)
strLine   =   strLine   &   "外发退货 "   &   chr(9)
strLine   =   strLine   &   "坏品区 "   &   chr(9)
strLine   =   strLine   &   "客户名称 "   &   chr(9)
strLine   =   strLine   &   "货品编号 "   &   chr(9)
MyFile.writeline   strLine
//===写内容===//
Do   While   Not   Rs.EOF
Call   GetTotalNum()
strLine= " "
strL