91网首页-91网页版-91网在线观看-91网站免费观看-91网站永久视频-91网站在线播放

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

ASP+模板生成Word、Excel、html

admin
2010年7月3日 14:12 本文熱度 6685
[p]用模板生成excel、word最大優(yōu)點(diǎn): [br][br] word、excel文檔樣式易于控制和調(diào)整,以往用excel.application來生成excel、word,需要寫很多代碼來控制排版的樣式,用模版幾乎不受任何限制,只需要打開word或excel,編輯文檔,選擇"文件->另存為web頁",即可方便的做好模板 ,用office生成的模板要比直接在dw中做好模板更加符合office偏好,生成后文件樣式可與原word、excel格式99%一樣,因此建議大家用office(office97~office2003)直接來生成模板框架。 [br][br]主要的代碼 [br]function.asp[/p] [p][/p] <%[br]'歡迎與我交流和學(xué)習(xí)[br]'作者:幸福的子彈[br]'blog:http://mysheji.com/blog[br]'e-mail:zhaojiangang@gmail.com[br]'qq:37294812[br]'-----------------------------------------------------------------------------[br]'開啟容錯機(jī)制 [br]on error resume next [br]'功能,檢測服務(wù)器是否支持指定組件[br]function object_install(strclassstring)[br]on error resume next[br]object_install=false[br]dim xtestobj[br]set xtestobj=server.createobject(strclassstring)[br]if -2147221005 <> err then object_install=true[br]set xtestobj=nothing[br]end function[br]if object_install("scripting.filesystemobject")=false then[br] response.write "
對不起,您的空間不支持fso組件,請與管理員聯(lián)系!
"[br] response.end[br]end if[br]if object_install("adodb.stream")=false then[br] response.write "
對不起,您的空間不支持adodb.stream功能,請與管理員聯(lián)系!
"[br] response.end[br]end if[br]'-----------------------------------------------------------------------------[br]'函數(shù)名稱:readtextfile[br]'作用:利用adodb.stream對象來讀取文本文件[br]'參數(shù):fileurl文件相對路徑,filecharset:文件編碼[br]function readfromtextfile (fileurl,filecharset)'函數(shù)[br] dim str[br] set stm=server.createobject("adodb.stream")[br] stm.type=2 '指定或返回的數(shù)據(jù)類型,[br] stm.mode=3 '指定打開模式,現(xiàn)在為可以讀寫模式,類似于word的只讀或鎖定功能[br] stm.charset=filecharset[br] stm.open[br] stm.loadfromfile server.mappath(fileurl)[br] str=stm.readtext[br] readfromtextfile=str[br]end function[br]'-----------------------------------------------------------------------------[br]'函數(shù)名稱:writetotextfile[br]'作用:利用adodb.stream對象來寫入文本文件[br]sub writetotextfile(fileurl,str,filecharset) '方法[br] set stm=server.createobject("adodb.stream")[br] stm.type=2 [br] stm.mode=3[br] stm.charset=filecharset[br] stm.open[br] stm.writetext str[br] stm.savetofile server.mappath(fileurl),2 [br] stm.flush[br]end sub[br]'-----------------------------------------------------------------------------[br]'功能:自動創(chuàng)建文件夾[br]'創(chuàng)建一級或多級目錄,可以創(chuàng)建不存在的根目錄[br]'參數(shù):要創(chuàng)建的目錄名稱,可以是多級[br]'返回邏輯值,true成功,false失敗[br]'創(chuàng)建目錄的根目錄從當(dāng)前目錄開始[br]function createmultifolder(byval cfolder)[br]dim objfso,phcreatefolder,createfolderarray,createfolder[br]dim i,ii,createfoldersub,phcreatefoldersub,blinfo[br]blinfo = false[br]createfolder = cfolder[br]on error resume next[br]set objfso = server.createobject("scripting.filesystemobject")[br]if err then[br]err.clear()[br]exit function[br]end if[br]createfolder = replace(createfolder,"","/")[br]if left(createfolder,1)="/" then[br]createfolder = right(createfolder,len(createfolder)-1)[br]end if[br]if right(createfolder,1)="/" then[br]createfolder = left(createfolder,len(createfolder)-1)[br]end if[br]createfolderarray = split(createfolder,"/")[br]for i = 0 to ubound(createfolderarray)[br]createfoldersub = ""[br]for ii = 0 to i[br]createfoldersub = createfoldersub & createfolderarray(ii) & "/"[br]next[br]phcreatefoldersub = server.mappath(createfoldersub)[br]if not objfso.folderexists(phcreatefoldersub) then[br]objfso.createfolder(phcreatefoldersub)[br]end if[br]next[br]if err then[br]err.clear()[br]else[br]blinfo = true[br]end if[br]createmultifolder = blinfo[br]end function[br]'點(diǎn)擊下載提示[br]function downloadfile(strfile)[br] strfilename = server.mappath(strfile)[br] response.buffer = true[br] response.clear[br] set s = server.createobject("adodb.stream")[br] s.open[br] s.type = 1[br] on error resume next[br] set fso = server.createobject("scripting.filesystemobject")[br] if not fso.fileexists(strfilename) then[br] response.write("

error:

" & strfilename & " does not exist

")[br] response.end[br] end if[br] set f = fso.getfile(strfilename)[br] intfilelength = f.size[br] s.loadfromfile(strfilename)[br] if err then[br] response.write("

error:

" & err.description & "

")[br] response.end[br] end if[br] response.addheader "content-disposition", "attachment; filename=" & f.name[br] response.addheader "content-length", intfilelength[br] response.charset = "utf-8"[br] response.contenttype = "application/octet-stream"[br] response.binarywrite s.read[br] response.flush[br] s.close[br] set s = nothing[br]end function[br]'-----------------------------------------------------------------------------[br]if err then[br] err.clear[br] set conn = nothing[br] response.write "

網(wǎng)站異常出錯,請與管理員聯(lián)系,謝謝!
"[br] response.end[br]end if[br]%> [p][br]生成word文檔:[/p] [p][/p] [p]<%[br]'創(chuàng)建文件[br]dim templatename,templatechar,filepath,filename,filecharset,templatecontent[br] templatename="template/template_word.htm" '模板名字,支持帶路徑,如"/moban/moban1.htm"或"temp/moban1.htm"[br] templatechar="gb2312" '模板文本的編碼[br] filepath="files/word/" '生成文件保存的路徑,當(dāng)前目錄請留空,其他目錄,路徑必須以“/”結(jié)尾[br] filename="doc1.doc" '即將生成的文件名[br] createmultifolder(filepath) '這一句用來判斷文件夾是否存在,沒有則自動創(chuàng)建,支持n級目錄[br] filecharset="gb2312" '打算生成的文本編碼[br]'讀取指定的模板內(nèi)容[br]templatecontent=readfromtextfile(templatename,templatechar) [br]'以下就交給你來替換模板內(nèi)容了[br]templatecontent=replace(templatecontent,"{$websitename}","藍(lán)色理想")[br]templatecontent=replace(templatecontent,"{$username}","幸福的子彈")[br]templatecontent=replace(templatecontent,"{$now}",now())[br]'其他內(nèi)容......[br]'最終調(diào)用函數(shù)來生成文件 [br]call writetotextfile(filepath&filename,templatecontent,filecharset) [br]'最后關(guān)閉adodb.stream對象[br]stm.flush[br]stm.close[br]set stm=nothing[br]downloadfile(filepath&filename)[br]%>[/p] [p]生成excel文檔:[/p] <%[br]'創(chuàng)建文件[br]dim templatename,templatechar,filepath,filename,filecharset,templatecontent[br] templatename="template/template_excel.htm" '模板名字,支持帶路徑,如"/moban/moban1.htm"或"temp/moban1.htm"[br] templatechar="gb2312" '模板文本的編碼[br] filepath="files/excel/" '生成文件保存的路徑,當(dāng)前目錄請留空,其他目錄,路徑必須以“/”結(jié)尾[br] filename="book1.xls" '即將生成的文件名[br] createmultifolder(filepath) '這一句用來判斷文件夾是否存在,沒有則自動創(chuàng)建,支持n級目錄[br] filecharset="gb2312" '打算生成的文本編碼[br]'讀取指定的模板內(nèi)容[br]templatecontent=readfromtextfile(templatename,templatechar) [br]'以下就交給你來替換模板內(nèi)容了[br]templatecontent=replace(templatecontent,"{$websitename}","藍(lán)色理想")[br]templatecontent=replace(templatecontent,"{$username}","幸福的子彈")[br]templatecontent=replace(templatecontent,"{$now}",now())[br]'其他內(nèi)容......[br]'最終調(diào)用函數(shù)來生成文件 [br]call writetotextfile(filepath&filename,templatecontent,filecharset) [br]'最后關(guān)閉adodb.stream對象[br]stm.flush[br]stm.close[br]set stm=nothing[br]downloadfile(filepath&filename)[br]%> [p][br]生成.htm靜態(tài)頁面[/p] <%[br]'創(chuàng)建文件[br]dim templatename,templatechar,filepath,filename,filecharset,templatecontent[br]templatename="template/template_html.htm" '模板名字,支持帶路徑,如"/moban/moban1.htm"或"temp/moban1.htm"[br]templatechar="gb2312" '模板文本的編碼[br]filepath="files/html/" '生成文件保存的路徑,當(dāng)前目錄請留空,其他目錄,路徑必須以“/”結(jié)尾[br]filename="untitled-1.htm" '即將生成的文件名[br]createmultifolder(filepath) '這一句用來判斷文件夾是否存在,沒有則自動創(chuàng)建,支持n級目錄[br]filecharset="gb2312" '打算生成的文本編碼[br]'讀取指定的模板內(nèi)容[br]templatecontent=readfromtextfile(templatename,templatechar) [br]'以下就交給你來替換模板內(nèi)容了[br]templatecontent=replace(templatecontent,"{$websitename}","藍(lán)色理想")[br]templatecontent=replace(templatecontent,"{$username}","幸福的子彈")[br]templatecontent=replace(templatecontent,"{$now}",now())[br]'其他內(nèi)容......[br]'最終調(diào)用函數(shù)來生成文件 [br]call writetotextfile(filepath&filename,templatecontent,filecharset) [br]'最后關(guān)閉adodb.stream對象[br]stm.flush[br]stm.close[br]set stm=nothing[br]response.write("恭喜您,"&filename&"已經(jīng)生成,點(diǎn)擊查看")[br]%> [p][/p] [p][url=http://sosuo8.com/article/upimages3/aspcreate.rar]打包下載[/url][upload=rar]201073141210-2.rar[/upload][/p]

該文章在 2010/7/3 14:12:15 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場、車隊、財務(wù)費(fèi)用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 国产美女脱的黄的全 | 日本成本人片免费 | 国产区精品 | 国产91免费精品电 | 日韩欧国产精 | 国产精品汇聚精彩 | 国产日韩欧美专区 | 福利所视频导航 | 91精品国产亚洲爽 | 三级国产在线观看 | 国产激情视频网站 | 91视频官 | 日本在线不卡视频 | 无码帝国www无码专 无码电影免费黄网站 | 不卡一卡 | 日本欧美一区 | 国语精品一区 | 91九色老熟女免费 | 岛国视频在线 | 日韩国产欧美看片 | 国产欧美另类 | www黄在线观看 | 日本一本免费一二区 | 国产高清成免费视频 | 国产欧美大片一区 | 果冻文化传媒官网 | 区国产高清在线 | 国产91一区| 欧美日韩在线一品道 | 午夜福利h | 国产日韩网站 | 欧美日韩电影一级 | 日韩欧美午夜 | 国产绿奴在线 | 精品国产欧美精品v | 日韩午夜电影在线 | 人成a大片在线观看 | 国产女精品| 日本免费看黄 | 国产九九热视频 | 中文字幕日韩专区 |