欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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>") 
%>

打包文件下載

相關(guān)文章

最新評論