一、用Excel对象,但要有Excel模板。速度略慢
<%
dim s,sql,filename,fs,myfile,x
Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("users.xls")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)
strSql = "select djh,bmmc,jihua,mubiao from scheme "
Set rstData =conn.execute(strSql)
if not rstData.EOF and not rstData.BOF then
dim trLine,responsestr
strLine=""
For each x in rstData.fields
strLine = strLine & x.name & chr(9)
Next
'--将表的列名先写入EXCEL
myfile.writeline strLine
Do while Not rstData.EOF
strLine=""
for each x in rstData.Fields
strLine = strLine & x.value & chr(9)
next
myfile.writeline strLine
rstData.MoveNext
loop
end if
Response.Write "生成EXCEL文件成功,点击下载!"
rstData.Close
set rstData = nothing
Conn.Close
Set Conn = nothing
%>
二、生成假的Excel,文件本身的格式是TXT,但扩展名使用的是XLS,用Excel也可以打开。速度快
<%
Response.ContentType="application/vnd.ms-excel "
%>
编号 | 日期 | 部门 | 工作计划 | 工作目标 |
<%=rs("djh")%> | <%=rs("rq")%> | <%=rs("bmmc")%> | <%=rs("jihua")%> | <%=rs("mubiao")%> |