ASP+模板生成Word、Excel、html的代码第1/2页(3)
'点击下载提示
function downloadFile(strFile)
strFilename = server.MapPath(strFile)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
on error resume next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
End Function
'-----------------------------------------------------------------------------
If Err Then
err.Clear
Set conn = Nothing
Response.Write "<div style='font-size:12px;color:#333;height:20px;line-height:20px;border:1px solid #DDCF8F;padding:6px;background:#FFFFED;font-family:verdana'>网站异常出错,请与管理员联系,谢谢!</div>"
Response.End
End If
%>
生成Word文档:
复制代码 代码如下:
<%
'创建文件
dim templateName,templatechar,filepath,filename,fileCharset,templateContent
templateName="template/template_word.htm" '模板名字,支持带路径,如"/moban/moban1.htm"或"temp/moban1.htm"
内容版权声明:除非注明,否则皆为本站原创文章。