页面导航: 首页网络编程ASP编程应用技巧 → 正文内容 ASP Word、Excel、html

ASP+模板生成Word、Excel、html的代码第2/2页

发布:dxy 字体:[增加 减小] 类型:转载
由于工作的需要,我需要为客户做一个在线生成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>")
%>

打包文件下载
当前2/2页 上一页12
浏览次数:载入中... 打印本文关闭本文返回首页

文章评论

共有 位脚本之家网友发表了评论我来说两句

同 类 文 章
最 近 更 新
热 点 排 行