av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

ASP教程之導(dǎo)出Excel數(shù)據(jù)的四種方法

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

一、使用OWC

什么是OWC?

OWC是office Web Compent的縮寫,即Microsoft的office Web組件,它為在Web中繪制圖形提供了靈活的同時(shí)也是最基本的機(jī)制。在一個(gè)intranet環(huán)境中,如果可以假設(shè)客戶機(jī)上存在特定的瀏覽器和一些功能強(qiáng)大的軟件(如IE5和office 2000),那么就有能力利用office Web組件提供一個(gè)交互式圖形開(kāi)發(fā)環(huán)境。這種模式下,客戶端工作站將在整個(gè)任務(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 "在保存過(guò)程中有錯(cuò)誤!" 
  87. End If 
  88. Set objExcel = Nothing 
  89. objRS.Close 
  90. Set objRS = Nothing 
  91. %> 

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

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

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

 
 
 
  1.  

導(dǎo)出到Excel代碼

 
 
 
  1.  
  2.  
  3.   導(dǎo)出到word代碼
  4.  
  5. Sub buildDoc 
  6. set table = document.all.data 
  7. row = table.rows.length 
  8. column = table.rows(1).cells.length
  9. Set objwordDoc = CreateObject("word.Document")
  10. objwordDoc.Application.Documents.Add theTemplate, False 
  11. objwordDoc.Application.Visible=True
  12. Dim theArray(20,10000) 
  13. for i=0 to row-1 
  14. for j=0 to column-1 
  15. theArray(j+1,i+1) = table.rows(i).cells(j).innerTEXT 
  16. next 
  17. next 
  18. objwordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("綜合查詢結(jié)果集") //顯示表格標(biāo)題
  19. objwordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("") 
  20. Set rngPara = objwordDoc.Application.ActiveDocument.Paragraphs(1).Range 
  21. With rngPara 
  22. .Bold = True //將標(biāo)題設(shè)為粗體 
  23. .ParagraphFormat.Alignment = 1 //將標(biāo)題居中 
  24. .Font.Name = "隸書" //設(shè)定標(biāo)題字體 
  25. .Font.Size = 18 //設(shè)定標(biāo)題字體大小 
  26. End With 
  27. Set rngCurrent = objwordDoc.Application.ActiveDocument.Paragraphs(3).Range 
  28. Set tabCurrent = ObjwordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,row,column)
  29. for i = 1 to column
  30. objwordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAfter theArray(i,1) 
  31. objwordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1 
  32. next 
  33. For i =1 to column 
  34. For j = 2 to row 
  35. objwordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.InsertAfter theArray(i,j) 
  36. objwordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.ParagraphFormat.alignment=1 
  37. Next 
  38. Next
  39. End Sub 
  40.  

三、直接在IE中打開(kāi),再存為Excel文件

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

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

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

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

注意:顯示的頁(yè)面中,只把

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

四、導(dǎo)出以半角逗號(hào)隔開(kāi)的csv

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

CSV文件介紹 (逗號(hào)分隔文件)

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

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

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


新聞名稱:ASP教程之導(dǎo)出Excel數(shù)據(jù)的四種方法
鏈接分享:http://uogjgqi.cn/article/dhcihes.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流

      1. <noframes id="nuvuf">