国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
如何使用 ASP 構(gòu)建在客戶端顯示的 XML 表格

如何使用 ASP 構(gòu)建在客戶端顯示的 XML 表格

文章編號 : 288130
最后修改 : 2005年12月6日
修訂 : 4.2

概要

本文介紹了 Active Server Pages (ASP) 腳本,這種腳本可通過 Office 電子表格組件以 XML 表格 (XMLSS) 格式構(gòu)建電子表格。XMLSS 可在客戶端通過以下方式之一顯示:
在網(wǎng)頁上的電子表格組件中顯示。
在瀏覽器內(nèi)置的 Microsoft Excel 中顯示。
直接在 Microsoft Excel 中打開。

回到頂端

更多信息

與服務(wù)器端 Microsoft Excel自動化相比,使用服務(wù)器端代碼中的電子表格組件構(gòu)建電子表格可提供更強的伸縮性和更好的性能。Microsoft 不推薦在服務(wù)器上自動化Office 應(yīng)用程序(包括 Excel),如果使用其他方法可以獲得相同結(jié)果,應(yīng)避免這種做法。XMLSS 可以保留電子表格組件和Microsoft Excel 的許多通用功能,例如,含多個工作表的工作簿、單元格格式、自動篩選、單元格公式和重新計算功能。電子表格組件具有與Microsoft Excel 對象模型非常匹配的對象模型。因此,如果您熟悉 Excel 對象模型,則可以輕松應(yīng)用一些現(xiàn)有的 Excel代碼,并進行修改以用于電子表格組件。

以下示例說明了如何使用電子表格組件和 ASP 在 XMLSS 中生成含多個工作表的工作簿。該示例還討論了如何在網(wǎng)頁或 Microsoft Excel 中顯示生成的 XMLSS 客戶端。

使用電子表格組件構(gòu)建 XMLSS 的 ASP 腳本

將下面的 ASP 另存為 XMLSS.asp,并保存在 Web 服務(wù)器的虛擬根目錄中(默認(rèn)的根目錄為 c:\inetpub\wwwroot):
<% Language=VBScript %><%Response.Buffer = TrueResponse.ContentType = "text/xml"Dim NumOrders, NumProds, rNumOrders = 300NumProds = 10Dim oSSDim oOrdersSheetDim oTotalsSheetDim oRangeDim cSet oSS = CreateObject("OWC10.Spreadsheet")Set c = oSS.Constants‘Rename Sheet1 to "Orders", rename Sheet2 to "Totals" and remove Sheet3Set oOrdersSheet = oSS.Worksheets(1)oOrdersSheet.Name = "Orders"Set oTotalsSheet = oSS.Worksheets(2)oTotalsSheet.Name = "Totals"oSS.Worksheets(3).Delete‘=== Build the First Worksheet (Orders) ==============================================‘Add headings to A1:F1 of the Orders worksheet and apply formattingSet oRange = oOrdersSheet.Range("A1:F1")oRange.Value = Array("Order Number", "Product ID", "Quantity", "Price", "Discount", "Total")oRange.Font.Bold = TrueoRange.Interior.Color = "Silver"oRange.Borders(c.xlEdgeBottom).Weight = c.xlThickoRange.HorizontalAlignment = c.xlHAlignCenter‘Apply formatting to the columnsoOrdersSheet.Range("A:A").ColumnWidth = 20oOrdersSheet.Range("B:E").ColumnWidth = 15oOrdersSheet.Range("F:F").ColumnWidth = 20oOrdersSheet.Range("A2:E" & NumOrders + 1 _).HorizontalAlignment = c.xlHAlignCenteroOrdersSheet.Range("D2:D" & NumOrders + 1).NumberFormat = "0.00"oOrdersSheet.Range("E2:E" & NumOrders + 1).NumberFormat = "0 % "oOrdersSheet.Range("F2:F" & NumOrders + 1).NumberFormat = "$ 0.00" ‘"_($* #,##0.00_)"‘Obtain the order information for the first five columns in the Orders worksheet‘a(chǎn)nd populate the worksheet with that data starting at row 2Dim aOrderDataaOrderData = GetOrderInfooOrdersSheet.Range("A2:E" & NumOrders + 1).Value = aOrderData‘Add a formula to calculate the order total for each row and format the columnoOrdersSheet.Range("F2:F" & NumOrders + 1).Formula = "=C2*D2*(1-E2)"oOrdersSheet.Range("F2:F" & NumOrders + 1).NumberFormat = "_(  $* #,##0.00   _)"‘Apply a border to the used rowsoOrdersSheet.UsedRange.Borders(c.xlInsideHorizontal).Weight = c.xlThinoOrdersSheet.UsedRange.BorderAround , c.xlThin, 15‘Turn on AutoFilter and display an initial criteria where‘the Product ID (column 2) is equal to 5oOrdersSheet.UsedRange.AutoFilteroOrdersSheet.AutoFilter.Filters(2).Criteria.FilterFunction = c.ssFilterFunctionIncludeoOrdersSheet.AutoFilter.Filters(2).Criteria.Add "5"oOrdersSheet.AutoFilter.Apply‘Add a Subtotal at the end of the usedrangeoOrdersSheet.Range("F" & NumOrders + 3).Formula = "=SUBTOTAL(9, F2:F" & NumOrders + 1 & ")"‘Apply window settings for the Orders worksheetoOrdersSheet.Activate   ‘Makes the Orders sheet activeoSS.Windows(1).ViewableRange = oOrdersSheet.UsedRange.AddressoSS.Windows(1).DisplayRowHeadings = FalseoSS.Windows(1).DisplayColumnHeadings = FalseoSS.Windows(1).FreezePanes = TrueoSS.Windows(1).DisplayGridlines = False‘=== Build the Second Worksheet (Totals) ===========================================‘Change the Column headings and hide row headingsoTotalsSheet.ActivateoSS.Windows(1).ColumnHeadings(1).Caption = "Product ID"oSS.Windows(1).ColumnHeadings(2).Caption = "Total"oSS.Windows(1).DisplayRowHeadings = False‘Add the product IDs to column 1Dim aProductIDsaProductIDs = GetProductIDsoTotalsSheet.Range("A1:A" & NumProds).Value = aProductIDsoTotalsSheet.Range("A1:A" & NumProds).HorizontalAlignment = c.xlHAlignCenter‘Add a formula to column 2 that computes totals per product from the Orders SheetoTotalsSheet.Range("B1:B" & NumProds).Formula = _"=SUMIF(Orders!B$2:B$" & NumOrders + 1 & ",A1,Orders!F$2:F$" & NumOrders + 1 & ")"oTotalsSheet.Range("B1:B" & NumProds).NumberFormat = "_(  $* #,##0.00   _)"‘Apply window settings for the Totals worksheetoSS.Windows(1).ViewableRange = oTotalsSheet.UsedRange.Address‘=== Setup for final presentation ==================================================oSS.DisplayToolbar = FalseoSS.AutoFit = TrueoOrdersSheet.ActivateResponse.Write oSS.XMLDataResponse.EndFunction GetOrderInfo()ReDim aOrderInfo(NumOrders,5)Dim aPrice, aDiscaPrice = Array(10.25, 9.5, 2.34, 6.57, 9.87, 4.55, 6, 13.05, 3.3, 5.5)aDisc = Array(0, 0.1, 0.15, 0.2)For r = 0 To NumOrders-1aOrderInfo(r, 0) = "‘" & String(7-Len(CStr(r+1)), "0") & r+1 ‘Col 1 is Order NumberaOrderInfo(r, 1) = Int(Rnd() * NumProds) + 1                 ‘Col 2 is Product IDaOrderInfo(r, 2) = Int(Rnd() * 20) + 1                       ‘Col 3 is QuantityaOrderInfo(r, 3) = aPrice(aOrderInfo(r, 1)-1)                ‘Col 4 is PriceaOrderInfo(r, 4) = aDisc(Int(Rnd() * 4))                     ‘Col 5 is DiscountNextGetOrderInfo = aOrderInfoEnd FunctionFunction GetProductIDs()ReDim aPIDs(NumProds, 1)For r = 0 To NumProds-1aPIDs(r, 0) = r+1NextGetProductIDs = aPIDsEnd Function%>

在網(wǎng)頁上顯示 XMLSS

要在網(wǎng)頁上顯示示例 XMLSS,只需將電子表格組件的 XMLURL 屬性設(shè)置為 ASP 的 URL,如下所示:
<html><body><object classid="clsid:0002E551-0000-0000-C000-000000000046" id="Spreadsheet1"><param name="XMLURL" value="http://YourWebServer/xmlss.asp"></object></body></html>

注意:如果使用的是 Office 2003,則必須根據(jù)需要更改以上代碼中的 classid。

在上述 HTML 中,使用 <param> 標(biāo)記設(shè)置 XMLURL 屬性。如果需要,還可以在運行時設(shè)置 XMLURL 屬性:
   Spreadsheet1.XMLURL = "http://YourWebServer/xmlss.asp"

在 Microsoft Excel 中顯示 XMLSS

使用電子表格組件創(chuàng)建的 XMLSS 可以在 Microsoft Excel 中打開。在電子表格組件中實現(xiàn)的格式和功能可與 MicrosoftExcel 共享。有一些功能是電子表格組件支持而 Excel 不支持的(或 Excel 支持而電子表格組件不支持);Excel 未實現(xiàn)的任何XML 標(biāo)記或?qū)傩栽诖蜷_ XMLSS 時都將被忽略。

要在 Microsoft Excel 中查看示例 ASP 腳本的結(jié)果,請執(zhí)行下列操作:
1. 啟動 Microsoft Excel。
2. 文件菜單上,單擊打開。
3. 文件名框中,鍵入 http://YourWebServer/xmlss.asp,然后單擊打開。
檢查工作簿,在 Excel中打開該工作簿時您會注意到,運行時應(yīng)用的數(shù)據(jù)和格式都顯示在工作簿中。有一個例外情況:在電子表格組件中創(chuàng)建的標(biāo)題不會帶入Excel,因為這是電子表格組件的功能,而 Microsoft Excel 中不提供該功能。如果使用電子表格組件創(chuàng)建 XMLSS 以便在Excel 中顯示文件,請注意兩者各自支持的不同功能。

在 Microsoft Excel 中打開 ASP 創(chuàng)建的 XMLSS 的另一種方法是,在 ASP 中提供 Excel 多用途 Internet 郵件擴展 (MIME) 類型作為 ContentType。使用 Excel MIME 類型并瀏覽到 ASP 時,XMLSS 可在瀏覽器內(nèi)置的 Microsoft Excel 中顯示,如下所示:
1. 在文本編輯器中打開 XMLSS.asp。
2. 在腳本中找到以下行:
Response.ContentType = "text/xml"            
將其更改為:
Response.ContentType = "application/vnd.ms-excel"            
3. 保存對 XMLSS.asp 所做的更改并啟動 Internet Explorer (IE)。
4. 瀏覽到 http://YourWebServer/XMLSS.asp。XML 表格將在瀏覽器內(nèi)置的 Microsoft Excel 中顯示。

回到頂端

參考

有關(guān)其他信息,請訪問下面的 Microsoft 網(wǎng)站,查看 Office Web Components 主題:
http://support.microsoft.com/ofd (http://support.microsoft.com/ofd)
有關(guān)其他信息,請單擊下面的文章編號,以查看 Microsoft 知識庫中相應(yīng)的文章:
285891 (http://support.microsoft.com/kb/285891/)如何使用 Visual Basic 或 ASP 創(chuàng)建 Excel 2002 和 Excel 2003 的 XML 表格
278976 (http://support.microsoft.com/kb/278976/) 如何使用 XSL 轉(zhuǎn)換在服務(wù)器端使用的 Excel XML 表格
257757 (http://support.microsoft.com/kb/257757/) 服務(wù)器端 Office 自動化應(yīng)考慮的因素
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Excel 2003 視頻教程
利用word將PDF轉(zhuǎn)換DOC文件的方法 --電腦高手
C# 操作 Excel 要點
excel2019 mac版本 excel2019激活密鑰(安裝教程)
Office電子表格經(jīng)典教程
Office組件輕松把PDF文件轉(zhuǎn)成Word文檔
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服