ASP+模板生成Word、Excel、html的代碼第2/2頁
更新時間:2008年06月18日 20:43:28 作者:
由于工作的需要,我需要為客戶做一個在線生成Excel及Word報表程序,參考了網上很多辦法
生成Excel文檔:
復制代碼 代碼如下:
<%
'創(chuàng)建文件
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) '這一句用來判斷文件夾是否存在,沒有則自動創(chuàng)建,支持n級目錄
fileCharset="gb2312" '打算生成的文本編碼
'讀取指定的模板內容
templateContent=ReadFromTextFile(templateName,templatechar)
'以下就交給你來替換模板內容了
templateContent=replace(templateContent,"{$websiteName}","藍色理想")
templateContent=replace(templateContent,"{$userName}","幸福的子彈")
templateContent=replace(templateContent,"{$now}",Now())
'其他內容......
'最終調用函數(shù)來生成文件
Call WriteToTextFile(filepath&filename,templateContent,fileCharset)
'最后關閉adodb.stream對象
stm.flush
stm.Close
set stm=nothing
downloadFile(filepath&filename)
%>
生成.htm靜態(tài)頁面
復制代碼 代碼如下:
<%
'創(chuàng)建文件
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) '這一句用來判斷文件夾是否存在,沒有則自動創(chuàng)建,支持n級目錄
fileCharset="gb2312" '打算生成的文本編碼
'讀取指定的模板內容
templateContent=ReadFromTextFile(templateName,templatechar)
'以下就交給你來替換模板內容了
templateContent=replace(templateContent,"{$websiteName}","藍色理想")
templateContent=replace(templateContent,"{$userName}","幸福的子彈")
templateContent=replace(templateContent,"{$now}",now())
'其他內容......
'最終調用函數(shù)來生成文件
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>")
%>
打包文件下載
您可能感興趣的文章:
相關文章
比較不錯的asp模板引終極講解(WEB開發(fā)之ASP模式)
比較不錯的asp模板引終極講解(WEB開發(fā)之ASP模式)...2007-08-08asp實現(xiàn)excel中的數(shù)據導入數(shù)據庫
本文給大家匯總介紹了使用asp實現(xiàn)將Excel中數(shù)據導入到數(shù)據庫中的方法,需要的朋友可以參考一下2015-09-09