ASP+模板生成Word、Excel、html的代码
更新时间:2008年06月18日 20:43:28 作者:
由于工作的需要,我需要为客户做一个在线生成Excel及Word报表程序,参考了网上很多办法
生成Excel文档:
复制代码 代码如下:
<%
'创建文件
dim templateName,templatechar,filepath,filename,fileCharset,templateContent
templateName="template/template_excel.htm" '模板名字,支持带路径,如"/moban/moban1.htm"或"temp/moban1.htm"
templatechar="gb2312" '模板文本的编码
filepath="files/excel/" '生成文件保存的路径,当前目录请留空,其他目录,路径必须以“/”结尾
filename="Book1.xls" '即将生成的文件名
CreateMultiFolder(filepath) '这一句用来判断文件夹是否存在,没有则自动创建,支持n级目录
fileCharset="gb2312" '打算生成的文本编码
'读取指定的模板内容
templateContent=ReadFromTextFile(templateName,templatechar)
'以下就交给你来替换模板内容了
templateContent=replace(templateContent,"{$websiteName}","蓝色理想")
templateContent=replace(templateContent,"{$userName}","幸福的子弹")
templateContent=replace(templateContent,"{$now}",Now())
'其他内容......
'最终调用函数来生成文件
Call WriteToTextFile(filepath&filename,templateContent,fileCharset)
'最后关闭adodb.stream对象
stm.flush
stm.Close
set stm=nothing
downloadFile(filepath&filename)
%>
生成.htm静态页面
复制代码 代码如下:
<%
'创建文件
dim templateName,templatechar,filepath,filename,fileCharset,templateContent
templateName="template/template_html.htm" '模板名字,支持带路径,如"/moban/moban1.htm"或"temp/moban1.htm"
templatechar="gb2312" '模板文本的编码
filepath="files/html/" '生成文件保存的路径,当前目录请留空,其他目录,路径必须以“/”结尾
filename="Untitled-1.htm" '即将生成的文件名
CreateMultiFolder(filepath) '这一句用来判断文件夹是否存在,没有则自动创建,支持n级目录
fileCharset="gb2312" '打算生成的文本编码
'读取指定的模板内容
templateContent=ReadFromTextFile(templateName,templatechar)
'以下就交给你来替换模板内容了
templateContent=replace(templateContent,"{$websiteName}","蓝色理想")
templateContent=replace(templateContent,"{$userName}","幸福的子弹")
templateContent=replace(templateContent,"{$now}",now())
'其他内容......
'最终调用函数来生成文件
Call WriteToTextFile(filepath&filename,templateContent,fileCharset)
'最后关闭adodb.stream对象
stm.flush
stm.Close
set stm=nothing
response.Write("恭喜您,"&filename&"已经生成,<a href="""&filepath&filename&""" target=""_blank"">点击查看</a>")
%>
打包文件下载


最新评论