明輝手游網(wǎng)中心:是一個免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

Programming MS Office 2000 Web Components首章第3節(jié)

[摘要]哪里可以使用這些組件? 既然Office Web Components都是COM控件,您會很自然的希望它們能夠在任何自稱是COM控件容器的環(huán)境中工作。然而,理論和現(xiàn)實(shí)不總是一致的,尤其...
哪里可以使用這些組件?



既然Office Web Components都是COM控件,您會很自然的希望它們能夠在任何自稱是COM控件容器的環(huán)境中工作。然而,理論和現(xiàn)實(shí)不總是一致的,尤其在軟件世界里。微軟公司創(chuàng)造了許多能夠包含控件的環(huán)境(我們小組脫口就能說出了16個),而別的公司創(chuàng)造了許多其它的環(huán)境。



為了避免Office的測試小組發(fā)狂,我們針對不同的容器,進(jìn)行不同的級別的Office Web Components測試。首先,我們挑選出那些我們認(rèn)為人們使用的最多的容器,進(jìn)行了充分的測試。然后,我們在不常使用的容器中進(jìn)行了基本的和特別的測試。最后,我們將一些容器組織起來,形成了一個”沒有經(jīng)過正式的測試,但是當(dāng)使用時不會產(chǎn)生災(zāi)難性后果”的范圍。表1-1顯示了這個范圍中的容器。

表 1-1. 經(jīng)過測試的容器.

Container
Test Coverage

Microsoft Internet Explorer 5.0
Full

Microsoft Internet Explorer 4.01
Full

Microsoft Internet Explorer 3.x
Not supported

Microsoft Visual Basic 6.0
Full

Microsoft Visual Basic 5.0
Basic

Microsoft Visual InterDev
Basic

Microsoft Access Forms
Basic

Microsoft Office UserForms
Basic

Microsoft FrontPage 99
Full

Microsoft FrontPage 98
Basic

Microsoft Access 2000 Data Access Page Designer
Full

Microsoft Script Editor
Full

Microsoft Word 2000
Basic

Microsoft Excel 2000
Basic

Microsoft PowerPoint 2000
Basic

Microsoft Outlook 2000
Basic

Microsoft Visual C++/MFC Projects
None

Microsoft Visual J++
None





還有,要注意在不同的容器中,控件的設(shè)計(jì)時行為很不相同。因?yàn)镺ffice Web Components是相當(dāng)復(fù)雜的控件,常常需要在控件內(nèi)部選擇元素(例如電子表格中的單元,數(shù)據(jù)透視報(bào)表中的透視字段,或圖表中的一系列數(shù)據(jù)點(diǎn)),以及格式化或處理這些元素。為了能夠?qū)崿F(xiàn)這個功能,在允許控件界面激活的容器中,控件會界面激活,這意味著這些控件會響應(yīng)鼠標(biāo)和鍵盤事件。在設(shè)計(jì)模式中針對控件所做的任何修改,都會在運(yùn)行期間重載控件時和文檔或窗體一起被保留,這就使得控件在被重置時顯得和您保存它們時完全一樣。一些容器在您點(diǎn)擊控件時立刻使控件界面激活。而另一些容器則要求雙擊控件。還有其它的一些容器要求您通過兩次單擊來激活這些控件。這些行為完全由容器所決定。因此請參考容器的文檔,以了解容器如何在設(shè)計(jì)階段處理COM控件。

請注意上述這些并不會影響控件運(yùn)行期間的行為。在運(yùn)行期間,所有的容器在加載了控件之后就會使控件界面激活。但是一些環(huán)境,例如Office文檔,因?yàn)槟偸窃诰庉嫯?dāng)前加載的文檔,所以永遠(yuǎn)也不會進(jìn)入運(yùn)行狀態(tài)。而Internet Exlporer,Visual Basic,Visual C++,Access Forms和Office用戶界面都具有運(yùn)行時模式,期間控件會立刻被激活。



數(shù)據(jù)存取頁和Internet Explorer 5

如果您閱讀任何Access2000的文檔,您很可能看到一些聲明,告訴您只能在Internet Explorer5或更高版本中瀏覽數(shù)據(jù)存取頁。雖然這是真的,但是這個聲明一般并不適用于Office Web Components。這些組件可以在Internet Explorer 4.01及以上版本中使用,然而它們不能在任何較早版本中使用(4.0,3.x,2.x等等)。這個版本要求也適用于任何使用Excel2000創(chuàng)建的交互內(nèi)容(創(chuàng)建過程使用Office Web Components),也適用于使用這些組件開發(fā)出的定制解決方案。數(shù)據(jù)存取頁需要Internet Explorer5中一些特殊的特性,這就是為什么它們只能在這個環(huán)境中運(yùn)行。然而,Office Web Components本身可以很好的在上面所列的那些經(jīng)過測試的容器中使用。



在服務(wù)器上使用Office Web Components

前文提到過,Office Web Components即能夠以控件的形式駐留在窗體,文檔或網(wǎng)頁中,也可以以無用戶界面的對象的形式駐留在內(nèi)存中。每個控件都提供一個屬性或者方法以返回控件當(dāng)前內(nèi)容的靜態(tài)表現(xiàn)形式。圖表和數(shù)據(jù)透視表控件可以創(chuàng)建它們內(nèi)容的GIF圖形,而電子表格控件可以返回一個HTML的表格片斷或者一個完整地頁面,這個片斷或者頁面可以在任何與HTML3.2兼容的瀏覽器中顯示。所有這些都意味這您可以在web服務(wù)器上使用這些控件,實(shí)現(xiàn)服務(wù)器端的圖表圖形和數(shù)據(jù)透視報(bào)表的生成,或?qū)崿F(xiàn)服務(wù)器端的電子表格模型重算功能。我會在本書第二部分演示一些這類技巧。



除了討論如何在服務(wù)器上使用這些控件之外,我們也會在本書后部考察許多更精細(xì)的問題,例如性能,可伸縮性和可靠性。



部 署

基于web的解決方案最具吸引力的方面之一就是不需要應(yīng)用程序的顯示安裝。需要做的事情要么是以腳本的形式在頁面中編程,要么是以applets或者com控件的形式自動下載。Office Web Components通過使用Internet Explorer的codebase特征,可以實(shí)現(xiàn)無需安裝的部署和自動的更新機(jī)制。這些組件也包括一個成熟的web安裝工具,使得下載的過程十分有意思。還有,OWC在技術(shù)上并不依賴于Office 2000,因此它能夠和Office97環(huán)境并存,也能在沒有安裝任何Office軟件的機(jī)器上使用。



在第12章會涉及到關(guān)于部署任務(wù)的各方面,以及如何建立自動部署OWC的解決方案。

Netscape Navigator怎么樣?



當(dāng)我在討論會和其它一些用戶聚會上講述Office Web Components時,總有人問這個問題:“這些組件可以在Netscape Navigator中運(yùn)行嗎?”答案是明確的“不行,”但是,這里有一些需要說明的地方。

Netscape Navigator 4.5本身并不支持COM控件,因此如果沒有安裝任何插件,Office Web Components甚至不能被Netscape navigaotor加載。然而,一個名為NCompass Labs的公司為Netscape Navigator開發(fā)了一個控件,使得Netscape Navigator可以在web頁面中控制COM控件。那么,如果您安裝了這個插件,您就能夠在Netscape Navigator中使用這些組件了嗎?答案是“看情況”,這里又有一些需要說明的。



您可能使用OWC建立許多包含了組件間通訊的解決方案――例如,綁定到一個數(shù)據(jù)透視表或者電子表格上的圖表,或是綁定到頁面上其它元素屬性上的一個電子表格單元。這些解決方案需要Internet Explorer提供的功能的支持。而即使是安裝了NCompass插件的Netscape Navigator也不能提供這些功能,因此這些解決方案完全不能在Netscape Navigator中工作。



使用單個的組件或是使用相互間不通訊的多個組件的解決方案,是可能在Netscape Navigator中成功運(yùn)行的。然而,這是我們的測試小組沒有研究的容器之一,因此我不能保證它會成功。



您應(yīng)該還記得,無論如何,由服務(wù)器上的控件產(chǎn)生的靜態(tài)內(nèi)容可以在Netscape Navigator和Internet Explorer中顯示。因此如果您的運(yùn)行環(huán)境需要支持兩個瀏覽器,您可能會對在web server上使用這些組件的方法以及展示了實(shí)現(xiàn)這些功能的技術(shù)的解決方案感興趣。







附錄:英文原文



Where Can You Use the Components?



Since the Office Web Components are COM controls, you'd naturally expect them to work in any environment that called itself a COM control container. However, theory and reality don't always match up, especially in the world of software. Microsoft makes many environments that can contain controls (16 that our team could recall off the top of our heads), and various other companies create many others.

To keep the Office test team from going mad, we tested the Office Web Components at different levels in different containers. First, we picked the containers we thought people would use most and performed full test passes on them. We then performed basic, ad hoc testing on the containers used less often. And finally, we grouped a few containers into the "not formally tested but doesn't cause a nuclear meltdown when tried" category. Table 1-1 shows which containers fell into what category.

Table 1-1. Tested containers.

Container
Test Coverage

Microsoft Internet Explorer 5.0
Full

Microsoft Internet Explorer 4.01
Full

Microsoft Internet Explorer 3.x
Not supported

Microsoft Visual Basic 6.0
Full

Microsoft Visual Basic 5.0
Basic

Microsoft Visual InterDev
Basic

Microsoft Access Forms
Basic

Microsoft Office UserForms
Basic

Microsoft FrontPage 99
Full

Microsoft FrontPage 98
Basic

Microsoft Access 2000 Data Access Page Designer
Full

Microsoft Script Editor
Full

Microsoft Word 2000
Basic

Microsoft Excel 2000
Basic

Microsoft PowerPoint 2000
Basic

Microsoft Outlook 2000
Basic

Microsoft Visual C++/MFC Projects
None

Microsoft Visual J++
None



Also note that the design-time activation of the controls varies quite a bit from container to container. Since the Office Web Components are fairly complex controls, it is often necessary to select elements within a control (such as a cell in a spreadsheet, a pivot field in a PivotTable report, or a series of data points in a chart) and format or perform operations on them. To enable this functionality, the controls will become UI active in containers that allow this, meaning they will respond to mouse and keyboard events. Any changes made to the controls in design mode will persist with the document or form when it is reloaded at runtime, resetting the controls to look exactly as they did when you saved them. Some containers make the controls UI active as soon as you click them. Others require that you double-click the control before it becomes UI active. Still other containers require you to single-click them twice to activate them. This behavior is entirely determined by the container, so refer to the container's documentation to see how it deals with COM controls at design time.

Note that this does not affect a control's runtime behavior. At runtime, all containers make the controls UI active after loading them. But some environments, such as Office documents, never get into a runtime state because you are always editing the document that's currently loaded. Internet Explorer, Visual Basic, Visual C++, Access Forms, and Office UserForms all have a runtime mode in which the controls are immediately active.

Data Access Pages and Internet Explorer 5



If you read any of the Access 2000 documentation, you will likely see statements that say you can view data access pages only in Internet Explorer version 5 and above. Although true, that statement does not apply to the Office Web Components in general. The components will function in Internet Explorer 4.01 and above, though they won't function in any earlier versions (4.0, 3.x, 2.x, and so on). This applies to any interactive content created with Excel 2000 (which uses the Office Web Components) and to custom solutions developed using the components.

Data access pages rely on a few specific features in Internet Explorer 5, which is why they only run in that environment. However, the Office Web Components themselves can run quite happily in the tested containers listed earlier.

Using the Office Web Components on a Server



As mentioned before, the Office Web Components were designed to run both as controls "sited" within a form, document, or web page, and as objects in memory with no user interface. Each of the controls exposes a property or method that returns a static representation of its current content. The Chart and PivotTable controls can create GIF images of their content, and the Spreadsheet control can return an HTML table fragment or full page that can be rendered by any browser that's compatible with HTML 3.2. All of this means you can use the components on a web server to perform server-side generation of chart images and PivotTable reports or server-side recalculation of a spreadsheet model. I'll demonstrate a few of these techniques in Part II of the book.

Besides discussing the how-to of using the components on the server, we'll examine a number of more subtle issues related to performance, scalability, and reliability later in the book.

Deployment



One of the more attractive aspects of web-based solutions is that they don't require explicit setup of an application. Anything needed is either included with the web page in the form of scripts or is automatically downloaded as applets or COM controls. The Office Web Components enable a no-install deployment and automatic upgrade mechanism by using the codebase feature of Internet Explorer. The components also include a sophisticated web installing control that makes the download experience much more attractive. Furthermore, OWC has no technological dependency on Office 2000, so it can coexist in an Office 97 environment or be used on a machine that doesn't have any other part of Office installed.

I'll cover all the aspects of deployment and how you can build your solutions to automatically deploy OWC in Chapter 12.

What About Netscape Navigator?



When I talk about the Office Web Components at conferences or other customer gatherings, invariably someone asks the question, "Do these run in Netscape Navigator?" The answer is essentially "no," but it has a few caveats.

Netscape Navigator 4.5 does not natively support COM controls, so without any plug-ins, the Office Web Components won't even be loaded by Netscape Navigator. However, a company called NCompass Labs, Inc. makes a plug-in for Netscape Navigator that can host COM controls in a web page. So if you installed this plug-in, could you use the components in Netscape Navigator? The answer is "it depends" and, again, has a few caveats.

Many solutions you might build with OWC involve communication between the components—for instance, a chart bound to a PivotTable or spreadsheet, or a spreadsheet cell bound to the property of another element on the page. These solutions depend on functionality provided in Internet Explorer that isn't present in Netscape Navigator even with the NCompass plug-in, so they simply won't work in Netscape Navigator.

Using a single component or multiple components that do not communicate with one another is possible in Netscape Navigator. However, this is one of the containers that our test team did not research, so I can't guarantee that it will work.

You should always remember, however, that static content generated by the controls on the server can be rendered in either Netscape Navigator or Internet Explorer. So if your runtime environment requires that you support both browsers, you probably will be more interested in using the components on your web server and in the solutions that show the techniques that d