asp 悬赏求助导出excel表格,目前运行导出程序不停,重启电脑才停

丈二和尚阿尼纳 2018-07-15 11:17:15
<!doctype html>
<!--#include file="../Include/conig.asp"-->
<!--#include file="Admin_check.asp"-->
<%
if Instr(session("AdminPurview"),"|2018,")=0 then
response.write ("<font color='red')>你不具有该管理模块的操作权限,请返回!</font>")
response.end
end if
'========判断是否具有管理权限
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">

<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="keywords" content="">
<meta name="description" content="">
<title>导出</title>
<body>
<body>
<%
'dim conn,strconn
'strconn="driver={SQL Server};server=wen;uid=sa;pwd=;database=DB_Test"
'set conn=server.CreateObject("adodb.connection")
'conn.Open strconn

dim s,sql,filename,fs,myfile,x

Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("../BookXls/export.xls")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)

'Set rs = Server.CreateObject("ADODB.Recordset")
'--从数据库中把你想放到EXCEL中的数据查出来
'sql = "select * from Tb_Execl order by id desc"
'rs.Open sql,conn
StartTime = Request("start_date")
EndTime = Request("end_date")
StartEndTime = "AddTime between #"& StartTime &" 00:00:00# and #"& EndTime &" 23:59:59#"

strSql = "select * from Tru_s_Dossier"& StartEndTime & " order by id desc"
' where " & StartEndTime & " order by ID desc"
Set rstData = DataToRsStatic(conn,strSql)
if not rstData.EOF and not rstData.BOF then

dim trLine,responsestr

strLine = "编号" & chr(9) & "VIN" & chr(9) & "ND号" & chr(9) & "客户类别" & chr(9) & "车型" & chr(9) & "责任单位" & chr(9) & "故障描述" & chr(9) & "故障产生阶段" & chr(9) & "返修措施"& chr(9) & "添加时间"
'objSpreadsheet.Range("A1:F1").merge '合并单元格(单元区域)
'--将表的列名先写入EXCEL
myfile.writeline strLine

Do while Not rstData.EOF
strLine=""

strLine = rstData("id") & chr(9) & rstData("sVIN") & chr(9) & rstData("ND") & chr(9) & rstData("CustCate") & chr(9) & rstData("Frstdegree") & chr(9) & rstData("Cityid") & chr(9) &rstData("Fdescribe") & chr(9) &rstData("gzcsjd") & chr(9) &rstData("fxcs") & chr(9) &formatdate(rstData("AddTime")) & chr(9) & IfSendStr
myfile.writeline strLine
rstData.MoveNext
loop

end if

Response.Write "生成EXCEL文件成功,点击<a href=""../BookXls/export.xls"" target=""_blank"">下载</a>!"

rstData.Close
set rstData = nothing
Conn.Close
Set Conn = nothing
Function DataToRsStatic(Conn,strSql)
Dim RsStatic

Set DataToRsStatic = Nothing
If Conn Is Nothing Then
Exit Function
End If
Set RsStatic = CreateObject("ADODB.RecordSet")
RsStatic.CursorLocation = 3
RsStatic.Open strSql,Conn,3,3
If Err.Number <> 0 Then
Exit Function
End If
Set DataToRsStatic = RsStatic
End Function
%>
</BODY>
</HTML>
...全文
1070 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
99percent 2018-10-02
  • 打赏
  • 举报
回复
请问你的问题解决了吗?我也是遇到这个问题。我的数据一多,myfile.writeline strLine 出错。而且单元格内不能自动换行。这个有解决的办法吗?
hookee 2018-09-13
  • 打赏
  • 举报
回复
数据量过大的话用sqlserver本身的导出功能,不要在asp里做。
李睿_Lee 2018-07-25
  • 打赏
  • 举报
回复
好久没用asp了。
陷入死循环了?
你可以在循环里加入一个计数判断,超过了就停止,然后看看生成的数据是不是有异常?
  • 打赏
  • 举报
回复
引用 3 楼 hookee 的回复:
dim trLine --> dim strLine

strSql = "select * from Tru_s_Dossier"& StartEndTime & " order by id desc"
-->Tru_s_Dossier后面加空格
strSql = "select * from Tru_s_Dossier "& StartEndTime & " order by id desc"

数据库连接conn 这段注释掉的话, 连接怎么打开?
DataToRsStati 没必要用, 直接写代码打开记录集

if not rstData.EOF and not rstData.BOF then
-->
if not (rstData.EOF and rstData.BOF) then

<!--#include file="../Include/conig.asp"-->
<!--#include file="Admin_check.asp"-->
<%
if Instr(session("AdminPurview"),"|2018,")=0 then
response.write ("<font color='red')>你不具有该管理模块的操作权限,请返回!</font>")
response.end
end if
'========判断是否具有管理权限
%>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">

<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="keywords" content="">
<meta name="description" content="">
<title>报名导出</title>
<body>
<body>
<%
'dim conn,strconn
'strconn="driver={SQL Server};server=wen;uid=sa;pwd=;database=DB_Test"
'set conn=server.CreateObject("adodb.connection")
'conn.Open strconn

dim s,sql,filename,fs,myfile,x

Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("../BookXls/export.xls")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)

'Set rs = Server.CreateObject("ADODB.Recordset")
'--从数据库中把你想放到EXCEL中的数据查出来
'sql = "select * from Tb_Execl order by id desc"
rs.Open sql,conn
StartTime = Request("start_date")
EndTime = Request("end_date")
StartEndTime = "AddTime between #"& StartTime &" 00:00:00# and #"& EndTime &" 23:59:59#"

strSql = "select * from Tru_s_Dossier "& StartEndTime & " order by id desc"
' where " & StartEndTime & " order by ID desc"
'Set rstData = DataToRsStatic(conn,strSql)
'if not rstData.EOF and not rstData.BOF then
if not (rstData.EOF and rstData.BOF) then
dim strLine,responsestr
'strLine=""
'For each x in rstData.fields
' strLine = strLine & x.name & chr(9)
'Next
strLine = "编号" & chr(9) & "VIN" & chr(9) & "ND号" & chr(9) & "客户类别" & chr(9) & "车型" & chr(9) & "责任单位" & chr(9) & "故障描述" & chr(9) & "故障产生阶段" & chr(9) & "返修措施"& chr(9) & "添加时间"
'objSpreadsheet.Range("A1:F1").merge '合并单元格(单元区域)
'--将表的列名先写入EXCEL
myfile.writeline strLine

Do while Not rstData.EOF
strLine=""

'for each x in rstData.Fields
' strLine = strLine & x.value & chr(9)
'next
'--将表的数据写入EXCEL
'IfSendStr = "未"
'If rstData("IfSend") = 1 Then IfSendStr = "已"
'Remark = Replace(rstData("Remark"), vbCrlf, "")


'strLine = rstData("ID") & chr(9) & GetTableString("tb_User","username","ID",rstData("UserID")) & chr(9) & GetTableString("tb_Product","name","ID",rstData("ProductID")) & chr(9) & rstData("NeedNum") & chr(9) & rstData("NeedTime") & chr(9) & rstData("address") & chr(9) & Remark & chr(9) & rstData("AddTime") & chr(9) & IfSendStr
strLine = rstData("id") & chr(9) & rstData("sVIN") & chr(9) & rstData("ND") & chr(9) & rstData("CustCate") & chr(9) & rstData("Frstdegree") & chr(9) & rstData("Cityid") & chr(9) &rstData("Fdescribe") & chr(9) &rstData("gzcsjd") & chr(9) &rstData("fxcs") & chr(9) &formatdate(rstData("AddTime")) & chr(9) & IfSendStr
myfile.writeline strLine
rstData.MoveNext
loop

end if

Response.Write "生成EXCEL文件成功,点击<a href=""../BookXls/export.xls"" target=""_blank"">下载</a>!"

rstData.Close
set rstData = nothing
Conn.Close
Set Conn = nothing
Function DataToRsStatic(Conn,strSql)
Dim RsStatic

Set DataToRsStatic = Nothing
If Conn Is Nothing Then
Exit Function
End If
Set RsStatic = CreateObject("ADODB.RecordSet")
RsStatic.CursorLocation = 3
RsStatic.Open strSql,Conn,3,3
If Err.Number <> 0 Then
Exit Function
End If
Set DataToRsStatic = RsStatic
End Function
%>
</BODY>
</HTML>

可以生成表格了,一直生成停不下来呢,几百MB,必须重启电脑才行
hookee 2018-07-19
  • 打赏
  • 举报
回复
dim trLine --> dim strLine strSql = "select * from Tru_s_Dossier"& StartEndTime & " order by id desc" -->Tru_s_Dossier后面加空格 strSql = "select * from Tru_s_Dossier "& StartEndTime & " order by id desc" 数据库连接conn 这段注释掉的话, 连接怎么打开? DataToRsStati 没必要用, 直接写代码打开记录集 if not rstData.EOF and not rstData.BOF then --> if not (rstData.EOF and rstData.BOF) then
  • 打赏
  • 举报
回复
不是CRm,我打算用我的这个代码到asp中,能帮忙改一下吗?
IT界java小生 2018-07-16
  • 打赏
  • 举报
回复
你做的是CRM客户管理系统吗?
<a id="out" class="btn1">导出</a>
<script>
// 使用outerHTML属性获取整个table元素的HTML代码(包括<table>标签),然后包装成一个完整的HTML文档,设置charset为urf-8以防止中文乱码
//--------使用id方法
var html = "<html><head><meta charset='utf-8' /></head><body>" + document.getElementById("tab1").outerHTML+document.getElementById("tab2").outerHTML +"</body></html>";
// 实例化一个Blob对象,其构造函数的第一个参数是包含文件内容的数组,第二个参数是包含文件类型属性的对象
var blob = new Blob([html], { type: "application/vnd.ms-excel" });
//--------使用js方法
// var a = document.getElementsByTagName("a")[0];
var out = document.getElementById("out");
// 利用URL.createObjectURL()方法为a元素生成blob URL
out.href = URL.createObjectURL(blob);
// 设置文件名
out.download = "销售机会表.xls";
</script>
希望能对你有点帮助

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧