欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
介紹一種用ASP+模板生成Word、Excel、靜態(tài)頁(yè)面一種簡(jiǎn)單、靈活多變的辦法[原創(chuàng )] ...
由于工作的需要,我需要為客戶(hù)做一個(gè)在線(xiàn)生成Excel及Word報表程序,參考了網(wǎng)上很多辦法,大多數都是采用Excel.Application(http://www.blueidea.com/tech/program/2006/3547.asp)組件來(lái)生成,發(fā)現容易出錯,而且對于大多數和我一樣的菜鳥(niǎo)來(lái)說(shuō),比較麻煩,考慮到前些天用ASP+模板+adodb.stream生成靜態(tài)頁(yè)面的辦法,經(jīng)過(guò)多次嘗試,終于掌握了一種用ASP+模板生成Excel和word的新的辦法,先分享如下:
    用模板生成Excel、Word最大優(yōu)點(diǎn):
    Word、Excel文檔樣式易于控制和調整,以往用Excel.Application來(lái)生成Excel、Word,需要寫(xiě)很多代碼來(lái)控制排版的樣式,用模版幾乎不受任何限制,只需要打開(kāi)word或Excel,編輯文檔,選擇"文件->另存為web頁(yè)",即可方便的做好模板 ,用office生成的模板要比直接在DW中做好模板更加符合office偏好,生成后文件樣式可與原word、Excel格式99%一樣,因此建議大家用office(office97~office2003)直接來(lái)生成模板框架。

   演示:http://mysheji.com/aspCreate/
   主要的代碼
function.asp
 
代碼:
<%
'歡迎與我交流和學(xué)習
'作者:幸福的子彈
'BLOG:http://mysheji.com/blog
'E-mail:zhaojiangang@gmail.com
'QQ:37294812
'-----------------------------------------------------------------------------
'開(kāi)啟容錯機制
on error resume next
'功能,檢測服務(wù)器是否支持指定組件
Function object_install(strclassstring)
  on error resume next
  object_install=false
  dim xtestobj
  set xtestobj=server.createobject(strclassstring)
  if -2147221005 <> Err then object_install=true
  set xtestobj=nothing
end function
if object_install("Scripting.FileSystemobject")=false then
    Response.Write "<div style='font-size:12px;color:#333;height:20px;line-height:20px;border:1px solid #DDCF8F;padding:6px;background:#FFFFED;font-family:verdana'>對不起,您的空間不支持FSO組件,請與管理員聯(lián)系!</div>"
    Response.End
end if
if object_install("adodb.stream")=false then
    Response.Write "<div style='font-size:12px;color:#333;height:20px;line-height:20px;border:1px solid #DDCF8F;padding:6px;background:#FFFFED;font-family:verdana'>對不起,您的空間不支持adodb.stream功能,請與管理員聯(lián)系!</div>"
    Response.End
end if
'-----------------------------------------------------------------------------
'函數名稱(chēng):ReadTextFile
'作用:利用AdoDb.Stream對象來(lái)讀取文本文件
'參數:FileUrl文件相對路徑,FileCharSet:文件編碼
Function ReadFromTextFile (FileUrl,FileCharSet)'函數
    dim str
    set stm=server.CreateObject("adodb.stream")
    stm.Type=2 '指定或返回的數據類(lèi)型,
    stm.mode=3 '指定打開(kāi)模式,現在為可以讀寫(xiě)模式,類(lèi)似于word的只讀或鎖定功能
    stm.charset=FileCharSet
    stm.open
    stm.loadfromfile server.MapPath(FileUrl)
    str=stm.readtext
    ReadFromTextFile=str
End Function
'-----------------------------------------------------------------------------
'函數名稱(chēng):WriteToTextFile
'作用:利用AdoDb.Stream對象來(lái)寫(xiě)入文本文件
sub WriteToTextFile(FileUrl,Str,FileCharSet) '方法
    set stm=server.CreateObject("adodb.stream")
    stm.Type=2
    stm.mode=3
    stm.charset=FileCharSet
    stm.open
    stm.WriteText str
    stm.SaveToFile server.MapPath(FileUrl),2
    stm.flush
End sub
'-----------------------------------------------------------------------------
'功能:自動(dòng)創(chuàng )建文件夾
'創(chuàng )建一級或多級目錄,可以創(chuàng )建不存在的根目錄
'參數:要創(chuàng )建的目錄名稱(chēng),可以是多級
'返回邏輯值,True成功,False失敗
'創(chuàng )建目錄的根目錄從當前目錄開(kāi)始
Function CreateMultiFolder(ByVal CFolder)
Dim objFSO,PhCreateFolder,CreateFolderArray,CreateFolder
Dim i,ii,CreateFolderSub,PhCreateFolderSub,BlInfo
BlInfo = False
CreateFolder = CFolder
On Error Resume Next
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If Err Then
Err.Clear()
Exit Function
End If
CreateFolder = Replace(CreateFolder,"","/")
If Left(CreateFolder,1)="/" Then
CreateFolder = Right(CreateFolder,Len(CreateFolder)-1)
End If
If Right(CreateFolder,1)="/" Then
CreateFolder = Left(CreateFolder,Len(CreateFolder)-1)
End If
CreateFolderArray = Split(CreateFolder,"/")
For i = 0 to UBound(CreateFolderArray)
CreateFolderSub = ""
For ii = 0 to i
CreateFolderSub = CreateFolderSub & CreateFolderArray(ii) & "/"
Next
PhCreateFolderSub = Server.MapPath(CreateFolderSub)
If Not objFSO.FolderExists(PhCreateFolderSub) Then
objFSO.CreateFolder(PhCreateFolderSub)
End If
Next
If Err Then
Err.Clear()
Else
BlInfo = True
End If
CreateMultiFolder = BlInfo
End Function
'點(diǎn)擊下載提示
function downloadFile(strFile)
     strFilename = server.MapPath(strFile)
     Response.Buffer = True
     Response.Clear
     Set s = Server.CreateObject("ADODB.Stream")
     s.Open
     s.Type = 1
     on error resume next
     Set fso = Server.CreateObject("Scripting.FileSystemObject")
     if not fso.FileExists(strFilename) then
         Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
         Response.End
     end if
     Set f = fso.GetFile(strFilename)
     intFilelength = f.size
     s.LoadFromFile(strFilename)
     if err then
         Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
         Response.End
     end if
     Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
     Response.AddHeader "Content-Length", intFilelength
     Response.CharSet = "UTF-8"
     Response.ContentType = "application/octet-stream"
     Response.BinaryWrite s.Read
     Response.Flush
     s.Close
     Set s = Nothing
End Function
'-----------------------------------------------------------------------------
If Err Then
    err.Clear
    Set conn = Nothing
    Response.Write "<div style='font-size:12px;color:#333;height:20px;line-height:20px;border:1px solid #DDCF8F;padding:6px;background:#FFFFED;font-family:verdana'>網(wǎng)站異常出錯,請與管理員聯(lián)系,謝謝!</div>"
    Response.End
End If
%>
 

 

生成Word文檔:
 
<%
'創(chuàng )建文件
dim templateName,templatechar,filepath,filename,fileCharset,templateContent
   templateName="template/template_word.htm"        '模板名字,支持帶路徑,如"/moban/moban1.htm"或"temp/moban1.htm"
   templatechar="gb2312"                      '模板文本的編碼
   filepath="files/word/"                     '生成文件保存的路徑,當前目錄請留空,其他目錄,路徑必須以“/”結尾
   filename="Doc1.doc"                           '即將生成的文件名
   CreateMultiFolder(filepath)                '這一句用來(lái)判斷文件夾是否存在,沒(méi)有則自動(dòng)創(chuàng )建,支持n級目錄
   fileCharset="gb2312"                       '打算生成的文本編碼
'讀取指定的模板內容
templateContent=ReadFromTextFile(templateName,templatechar)   
'以下就交給你來(lái)替換模板內容了
templateContent=replace(templateContent,"{$websiteName}","藍色理想")
templateContent=replace(templateContent,"{$userName}","幸福的子彈")
templateContent=replace(templateContent,"{$now}",Now())
'其他內容......
'最終調用函數來(lái)生成文件         
Call WriteToTextFile(filepath&filename,templateContent,fileCharset)   
'最后關(guān)閉adodb.stream對象
stm.flush
stm.Close
set stm=nothing
downloadFile(filepath&filename)
%>
程序源碼:
aspCreate.rar (20.67 KB)

 

 

生成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)                '這一句用來(lái)判斷文件夾是否存在,沒(méi)有則自動(dòng)創(chuàng )建,支持n級目錄
   fileCharset="gb2312"                       '打算生成的文本編碼
'讀取指定的模板內容
templateContent=ReadFromTextFile(templateName,templatechar)   
'以下就交給你來(lái)替換模板內容了
templateContent=replace(templateContent,"{$websiteName}","藍色理想")
templateContent=replace(templateContent,"{$userName}","幸福的子彈")
templateContent=replace(templateContent,"{$now}",Now())
'其他內容......
'最終調用函數來(lái)生成文件         
Call WriteToTextFile(filepath&filename,templateContent,fileCharset)   
'最后關(guān)閉adodb.stream對象
stm.flush
stm.Close
set stm=nothing
downloadFile(filepath&filename)
%>
 

 

生成.htm靜態(tài)頁(yè)面
代碼:
<%
'創(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)                '這一句用來(lái)判斷文件夾是否存在,沒(méi)有則自動(dòng)創(chuàng )建,支持n級目錄
   fileCharset="gb2312"                       '打算生成的文本編碼
'讀取指定的模板內容
templateContent=ReadFromTextFile(templateName,templatechar)   
'以下就交給你來(lái)替換模板內容了
templateContent=replace(templateContent,"{$websiteName}","藍色理想")
templateContent=replace(templateContent,"{$userName}","幸福的子彈")
templateContent=replace(templateContent,"{$now}",now())
'其他內容......
'最終調用函數來(lái)生成文件         
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>")
%>
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
asp代碼實(shí)現EXCEL數據導入到SQL數據庫
用ASP上傳Excel 表格并導入到數據庫
找回斷電、死機前未儲存的Word,Excel文件
ASP生成靜態(tài)頁(yè)面的方法
excel中如何通過(guò)VBA打開(kāi)word文件和ppt文件?
ASP生成HTML-另一篇
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久