日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

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

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:ASP進(jìn)階:用asp做的簡單搜索引擎代碼
下面是庫中URLINDEX表:URL和Keywords字段分別添加了索引. URL 文本 (索引:有(無重復(fù))) Title 文本 Description 文本 Summary

一、使用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)容:

<%Option Explicit
Class ExcelGen
Private obJSPreadsheet
Private iColOffset

Private iRowOffset
Sub Class_Initialize()
Set obJSPreadsheet = Server.CreateObject("OWC.Spreadsheet")
iRowOffset = 2
iColOffset = 2
End Sub

Sub Class_Terminate()
Set obJSPreadsheet = Nothing 'Clean up
End Sub

Public Property Let ColumnOffset(iColOff)
If iColOff > 0 then
iColOffset = iColOff
Else
iColOffset = 2
End If
End Property

Public Property Let RowOffset(iRowOff)
If iRowOff > 0 then
iRowOffset = iRowOff
Else
iRowOffset = 2
End If
End Property Sub GenerateWorksheet(objRS)
'Populates the Excel worksheet based on a Recordset's contents
'Start by displaying the titles
If objRS.EOF then Exit Sub
Dim objField, iCol, iRow
iCol = iColOffset
iRow = iRowOffset
For Each objField in objRS.Fields
obJSPreadsheet.Cells(iRow, iCol).Value = objField.Name
obJSPreadsheet.Columns(iCol).AutoFitColumns
'設(shè)置Excel表里的字體
obJSPreadsheet.Cells(iRow, iCol).Font.Bold = True
obJSPreadsheet.Cells(iRow, iCol).Font.Italic = False
obJSPreadsheet.Cells(iRow, iCol).Font.Size = 10
obJSPreadsheet.Cells(iRow, iCol).Halignment = 2 '居中
iCol = iCol 1
Next 'objField
'Display all of the data
Do While Not objRS.EOF
iRow = iRow 1
iCol = iColOffset
For Each objField in objRS.Fields
If IsNull(objField.Value) then
obJSPreadsheet.Cells(iRow, iCol).Value = ""
Else
obJSPreadsheet.Cells(iRow, iCol).Value = objField.Value
obJSPreadsheet.Columns(iCol).AutoFitColumns
obJSPreadsheet.Cells(iRow, iCol).Font.Bold = False
obJSPreadsheet.Cells(iRow, iCol).Font.Italic = False
obJSPreadsheet.Cells(iRow, iCol).Font.Size = 10
End If
iCol = iCol 1
Next 'objField
objRS.MoveNext
Loop
End Sub Function SaveWorksheet(strFileName)

'Save the worksheet to a specified filename
On Error Resume Next
Call obJSPreadsheet.ActiveSheet.Export(strFileName, 0)
SaveWorksheet = (Err.Number = 0)
End Function
End Class

Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "SELECT * FROM xxxx", "Provider=SQLOLEDB.1;Persist Security

Info=True;User ID=xxxx;Password=xxxx;Initial Catalog=xxxx;Data source=xxxx;"
Dim SaveName
SaveName = Request.Cookies("savename")("name")
Dim objExcel
Dim ExcelPath
ExcelPath = "Excel\" & SaveName & ".xls"
Set objExcel = New ExcelGen
objExcel.RowOffset = 1
objExcel.ColumnOffset = 1
objExcel.GenerateWorksheet(objRS)
If objExcel.SaveWorksheet(Server.MapPath(ExcelPath)) then
'Response.Write "<HTML><body bgcolor='gainsboro' text='#000000'>已保存為Excel文件.

<a href=../../'" & server.URLEncode(ExcelPath) & "'>下載</a>"
Else
Response.Write "在保存過程中有錯誤!"
End If
Set objExcel = Nothing
objRS.Close
Set objRS = Nothing
%>

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

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

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

<input type="hidden" name="out_word" onclick="vbscript:buildDoc" value="導(dǎo)出到word" class="notPrint">
<input type="hidden" name="out_Excel" onclick="AutomateExcel();" value="導(dǎo)出到Excel" class="notPrint">

  導(dǎo)出到Excel代碼

<SCRIPT LANGUAGE="javascript">
<!--
function AutomateExcel()
{
// Start Excel and get Application object.
var oXL = new ActiveXObject("Excel.Application");
// Get a new workbook.
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var table = document.all.data;
var hang = table.rows.length;

var lie = table.rows(0).cells.length;

// Add table headers going cell by cell.
for (i=0;i<hang;i )
{
for (j=0;j<lie;j )
{
oSheet.Cells(i 1,j 1).value = table.rows(i).cells(j).innerText;
}

}
oXL.Visible = true;
oXL.UserControl = true;
}
//-->
</SCRIPT>

  導(dǎo)出到word代碼

<script language="vbscript">
Sub buildDoc
set table = document.all.data
row = table.rows.length
column = table.rows(1).cells.length

Set objwordDoc = CreateObject("word.Document")

objwordDoc.Application.Documents.Add theTemplate, False
objwordDoc.Application.Visible=True

Dim theArray(20,10000)
for i=0 to row-1
for j=0 to column-1
theArray(j 1,i 1) = table.rows(i).cells(j).innerTEXT
next
next
objwordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("綜合查詢結(jié)果集") //顯示表格標(biāo)題

objwordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("")
Set rngPara = objwordDoc.Application.ActiveDocument.Paragraphs(1).Range
With rngPara
.Bold = True //將標(biāo)題設(shè)為粗體
.ParagraphFormat.Alignment = 1 //將標(biāo)題居中
.Font.Name = "隸書" //設(shè)定標(biāo)題字體
.Font.Size = 18 //設(shè)定標(biāo)題字體大小
End With
Set rngCurrent = objwordDoc.Application.ActiveDocument.Paragraphs(3).Range
Set tabCurrent = ObjwordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,row,column)

for i = 1 to column

objwordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAfter theArray(i,1)
objwordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1
next
For i =1 to column
For j = 2 to row
objwordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.InsertAfter theArray(i,j)
objwordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.ParagraphFormat.alignment=1
Next
Next

End Sub
</SCRIPT>

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

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

把讀出的數(shù)據(jù)用<table>格式,在網(wǎng)頁中顯示出來,同時,加上下一句即可把Excel表在客客戶端顯示。

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

注意:顯示的頁面中,只把<table>輸出,最好不要輸出其他表格以外的信息。

四、導(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)擊它即可下載該文件。

請作者聯(lián)系本站,及時附注您的姓名。聯(lián)系郵箱:mb5u#vip.qq.com(把#改為@)。


分享:ASP 3.0高級編程(三十八)
8.3.3 使用連接狀態(tài) 將連接字符串存入應(yīng)用程序變量是一個常用的技巧,同使用一個包含文件一樣有效。例如,可以在global.asa文件中加入下面的代碼: Sub Application_OnStart() strConn = "

來源:模板無憂//所屬分類:ASP教程/更新時間:2008-08-22
相關(guān)ASP教程