ASP 生成xls excle
Set fs = server.createObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
'filename = Server.MapPath("temp/ria.xls")
filename = Server.MapPath(Application("DOWNLOADFILEURL") ) & "\DA_BudgetQuery_"& objUser.Account & ".xls"
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
'response.end
fs.deleteFile(filename)
end if
response.write "3<br />"
'--创建EXCEL文件
set myfile = fs.createTextFile(filename,true,true)
'stop
strSql = Request.QueryString("strSql")
'strSql = " exec RIAproRpt_NEW '"& strConn &"'"
Set conn2 = Server.Createobject("ADODB.Connection")
conn2.Open strCnn
Set conn3 = Server.Createobject("ADODB.Connection")
conn3.Open strCnn
Set tmpRs =conn.execute(strSql)
if not tmpRs.EOF and not tmpRs.BOF then
dim strLine,responsestr
strLine=""
strLine=strLine & "<table border=""1px"" cellspacing=""0"" cellpadding=""0"" style=""padding:0px; margin:0px"" > <tr > <td>区域</td>
'--将表的列名先写入EXCEL
myfile.WriteLine (strLine )
myfile.writeline("</table>")
Response.Write "生成EXCEL文件成功,点击<a href='"&Application("DOWNLOADFILEURL")& "\DA_BudgetQuery_"& objUser.Account & ".xls' >下载</a>!"
'Response.Write "生成EXCEL文件成功,点击<a href='Temp/RIA.xls' >下载</a>!"
'fs.close
set fs=nothing
myfile.close
set myfile=nothing
tmpRs.Close
set tmpRs = nothing
Conn.Close
Set Conn = nothing
posted on 2011-06-13 17:55 Henry_Wang 阅读(348) 评论(0) 编辑 收藏 举报