日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
ASP教程之導(dǎo)出Excel數(shù)據(jù)的四種方法

我們有時候需要把數(shù)據(jù)導(dǎo)出來,作為參考等等。下面就為你介紹,ASP導(dǎo)出Excel書籍的四種方法。

一、使用OWC

什么是OWC?

OWC是office Web Compent的縮寫,即Microsoft的office Web組件,它為在Web中繪制圖形提供了靈活的同時也是最基本的機(jī)制。在一個intranet環(huán)境中,如果可以假設(shè)客戶機(jī)上存在特定的瀏覽器和一些功能強(qiáng)大的軟件(如IE5和office 2000),那么就有能力利用office Web組件提供一個交互式圖形開發(fā)環(huán)境。這種模式下,客戶端工作站將在整個任務(wù)中分擔(dān)很大的比重。

以下為引用的內(nèi)容:

 
 
 
  1. <%Option Explicit 
  2. Class ExcelGen 
  3. Private obJSPreadsheet 
  4. Private iColOffset
  5. Private iRowOffset 
  6. Sub Class_Initialize() 
  7. Set obJSPreadsheet = Server.CreateObject("OWC.Spreadsheet") 
  8. iRowOffset = 2 
  9. iColOffset = 2 
  10. End Sub
  11. Sub Class_Terminate() 
  12. Set obJSPreadsheet = Nothing 'Clean up 
  13. End Sub
  14. Public Property Let ColumnOffset(iColOff) 
  15. If iColOff > 0 then 
  16. iColOffiColOffset = iColOff 
  17. Else 
  18. iColOffset = 2 
  19. End If 
  20. End Property
  21. Public Property Let RowOffset(iRowOff) 
  22. If iRowOff > 0 then 
  23. iRowOffiRowOffset = iRowOff 
  24. Else 
  25. iRowOffset = 2 
  26. End If 
  27. End Property Sub GenerateWorksheet(objRS) 
  28. 'Populates the Excel worksheet based on a Recordset's contents 
  29. 'Start by displaying the titles 
  30. If objRS.EOF then Exit Sub 
  31. Dim objField, iCol, iRow 
  32. iCol = iColOffset 
  33. iRow = iRowOffset 
  34. For Each objField in objRS.Fields 
  35. obJSPreadsheet.Cells(iRow, iCol).Value = objField.Name 
  36. obJSPreadsheet.Columns(iCol).AutoFitColumns 
  37. '設(shè)置Excel表里的字體 
  38. obJSPreadsheet.Cells(iRow, iCol).Font.Bold = True 
  39. obJSPreadsheet.Cells(iRow, iCol).Font.Italic = False 
  40. obJSPreadsheet.Cells(iRow, iCol).Font.Size = 10 
  41. obJSPreadsheet.Cells(iRow, iCol).Halignment = 2 '居中 
  42. iColiCol = iCol + 1 
  43. Next 'objField 
  44. 'Display all of the data 
  45. Do While Not objRS.EOF 
  46. iRowiRow = iRow + 1 
  47. iCol = iColOffset 
  48. For Each objField in objRS.Fields 
  49. If IsNull(objField.Value) then 
  50. obJSPreadsheet.Cells(iRow, iCol).Value = "" 
  51. Else 
  52. obJSPreadsheet.Cells(iRow, iCol).Value = objField.Value 
  53. obJSPreadsheet.Columns(iCol).AutoFitColumns 
  54. obJSPreadsheet.Cells(iRow, iCol).Font.Bold = False 
  55. obJSPreadsheet.Cells(iRow, iCol).Font.Italic = False 
  56. obJSPreadsheet.Cells(iRow, iCol).Font.Size = 10 
  57. End If 
  58. iColiCol = iCol + 1 
  59. Next 'objField 
  60. objRS.MoveNext 
  61. Loop 
  62. End Sub Function SaveWorksheet(strFileName)
  63. 'Save the worksheet to a specified filename 
  64. On Error Resume Next 
  65. Call obJSPreadsheet.ActiveSheet.Export(strFileName, 0) 
  66. SaveWorksheet = (Err.Number = 0) 
  67. End Function 
  68. End Class
  69. Dim objRS 
  70. Set objRS = Server.CreateObject("ADODB.Recordset") 
  71. objRS.Open "SELECT * FROM xxxx", "Provider=SQLOLEDB.1;Persist Security
  72. Info=True;User ID=xxxx;Password=xxxx;Initial Catalog=xxxx;Data source=xxxx;" 
  73. Dim SaveName 
  74. SaveName = Request.Cookies("savename")("name") 
  75. Dim objExcel 
  76. Dim ExcelPath 
  77. ExcelPath = "Excel\" & SaveName & ".xls" 
  78. Set objExcel = New ExcelGen 
  79. objExcel.RowOffset = 1 
  80. objExcel.ColumnOffset = 1 
  81. objExcel.GenerateWorksheet(objRS) 
  82. If objExcel.SaveWorksheet(Server.MapPath(ExcelPath)) then 
  83. 'Response.Write "已保存為Excel文件.
  84. 下載" 
  85. Else 
  86. Response.Write "在保存過程中有錯誤!" 
  87. End If 
  88. Set objExcel = Nothing 
  89. objRS.Close 
  90. Set objRS = Nothing 
  91. %> 

二、用Excel的Application組件在客戶端導(dǎo)出到Excel或word

以下為引用的內(nèi)容:

注意:兩個函數(shù)中的“data“是網(wǎng)頁中要導(dǎo)出的table的 id

 
 
 
  1.  

導(dǎo)出到Excel代碼

 
 
 
  1.   導(dǎo)出到word代碼
  2.  

三、直接在IE中打開,再存為Excel文件

以下為引用的內(nèi)容:

把讀出的數(shù)據(jù)用

格式,在網(wǎng)頁中顯示出來,同時,加上下一句即可把Excel表在客客戶端顯示。

<%response.ContentType ="application/vnd.ms-Excel"%>

注意:顯示的頁面中,只把

輸出,***不要輸出其他表格以外的信息。

四、導(dǎo)出以半角逗號隔開的csv

用fso方法生成文本文件的方法,生成一個擴(kuò)展名為csv文件。此文件,一行即為數(shù)據(jù)表的一行。生成數(shù)據(jù)表字段用半角逗號隔開。(有關(guān)fso生成文本文件的方法,在此就不做介紹了)

CSV文件介紹 (逗號分隔文件)

選擇該項(xiàng)系統(tǒng)將創(chuàng)建一個可供下載的CSV 文件; CSV是最通用的一種文件格式,它可以非常容易地被導(dǎo)入各種PC表格及數(shù)據(jù)庫中。

請注意即使選擇表格作為輸出格式,仍然可以將結(jié)果下載CSV文件。在表格輸出屏幕的底部,顯示有 "CSV 文件"選項(xiàng),點(diǎn)擊它即可下載該文件。

希望本文介紹的三種方法,能夠幫助到你。


文章標(biāo)題:ASP教程之導(dǎo)出Excel數(shù)據(jù)的四種方法
當(dāng)前地址:http://www.5511xx.com/article/dhcihes.html