ASP+模板生成Word、Excel、html的代碼第2/2頁
更新時間:2008年06月18日 20:43:28 作者:
由于工作的需要,我需要為客戶做一個在線生成Excel及Word報表程序,參考了網(wǎng)上很多辦法
生成Excel文檔:
復(fù)制代碼 代碼如下:
<%
'創(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/" '生成文件保存的路徑,當(dāng)前目錄請留空,其他目錄,路徑必須以“/”結(jié)尾
filename="Book1.xls" '即將生成的文件名
CreateMultiFolder(filepath) '這一句用來判斷文件夾是否存在,沒有則自動創(chuàng)建,支持n級目錄
fileCharset="gb2312" '打算生成的文本編碼
'讀取指定的模板內(nèi)容
templateContent=ReadFromTextFile(templateName,templatechar)
'以下就交給你來替換模板內(nèi)容了
templateContent=replace(templateContent,"{$websiteName}","藍(lán)色理想")
templateContent=replace(templateContent,"{$userName}","幸福的子彈")
templateContent=replace(templateContent,"{$now}",Now())
'其他內(nèi)容......
'最終調(diào)用函數(shù)來生成文件
Call WriteToTextFile(filepath&filename,templateContent,fileCharset)
'最后關(guān)閉adodb.stream對象
stm.flush
stm.Close
set stm=nothing
downloadFile(filepath&filename)
%>
生成.htm靜態(tài)頁面
復(fù)制代碼 代碼如下:
<%
'創(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/" '生成文件保存的路徑,當(dāng)前目錄請留空,其他目錄,路徑必須以“/”結(jié)尾
filename="Untitled-1.htm" '即將生成的文件名
CreateMultiFolder(filepath) '這一句用來判斷文件夾是否存在,沒有則自動創(chuàng)建,支持n級目錄
fileCharset="gb2312" '打算生成的文本編碼
'讀取指定的模板內(nèi)容
templateContent=ReadFromTextFile(templateName,templatechar)
'以下就交給你來替換模板內(nèi)容了
templateContent=replace(templateContent,"{$websiteName}","藍(lán)色理想")
templateContent=replace(templateContent,"{$userName}","幸福的子彈")
templateContent=replace(templateContent,"{$now}",now())
'其他內(nèi)容......
'最終調(diào)用函數(shù)來生成文件
Call WriteToTextFile(filepath&filename,templateContent,fileCharset)
'最后關(guān)閉adodb.stream對象
stm.flush
stm.Close
set stm=nothing
response.Write("恭喜您,"&filename&"已經(jīng)生成,<a href="""&filepath&filename&""" target=""_blank"">點(diǎn)擊查看</a>")
%>
打包文件下載
您可能感興趣的文章:
- php Smarty模板生成html文檔的方法
- JavaScript和ActionScript的交互實(shí)現(xiàn)代碼
- PHP JSON格式數(shù)據(jù)交互實(shí)例代碼詳解
- thinkPHP的Html模板標(biāo)簽使用方法
- 解析Android中webview和js之間的交互
- PHP與javascript實(shí)現(xiàn)變量交互的示例代碼
- 多種方式實(shí)現(xiàn)JS調(diào)用后臺方法進(jìn)行數(shù)據(jù)交互
- extjs中form與grid交互數(shù)據(jù)(record)的方法
- C#.NET采用HTML模板發(fā)送電子郵件完整實(shí)例
- 基于HTML模板和JSON數(shù)據(jù)的JavaScript交互(移動端)
相關(guān)文章
比較不錯的asp模板引終極講解(WEB開發(fā)之ASP模式)
比較不錯的asp模板引終極講解(WEB開發(fā)之ASP模式)...2007-08-08asp實(shí)現(xiàn)excel中的數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫
本文給大家匯總介紹了使用asp實(shí)現(xiàn)將Excel中數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫中的方法,需要的朋友可以參考一下2015-09-09