Programming Microsoft Office 2000 Web Components第一章第一節

來源:互聯網
上載者:User
web 第一章第二節 Office Web Components是什麼?

Office Web Components是一組的COM控制項,設計的目的是為眾多的控制項容器提供互動的試算表建模,資料報表和資料視覺效果功能。OWC庫包含四個主要的組件:工作表元件,圖表組件,透視表組件和資料來源組件。我們將在這一節中簡要論述每個控制項,然後在後續各章中討論更多細節。



注釋:

COM也被稱作ActiveX。當微軟發明了術語”ActiveX”來描述COM技術時,我正在Visual Basic小組,這個術語使得我們絕大部分的客戶大吃一驚,因為這些客戶在我們停止使用術語”OLE”後剛剛習慣於使用術語COM。我不是市場人員,所以本書中我只使用術語COM來描述元件物件模型技術。



“Office Web Components”名稱中的單詞”Office”表示這些控制項就是由那些開發微軟Excel和Access的程式員中的一部分人開發的,並且這些控制項被設計成在外觀,使用感受和行為表現上就像是他們的微軟Office兄弟的精簡版一樣。這些控制項確實不包含Excel和Access中的所有的功能——換句話說,您也不會為了在瀏覽器中查看一個報表而動態下載完整的Excel和Access!然而,這些控制項也確實包含了許多的常用功能,尤其是那些在與已有內容進行互動時所必需的功能。此外,這些控制項還能夠讀寫Excel 2000的HTML格式的檔案,允許使用者點擊一個按鈕,將當前的資料載入到Excel中,以便作更加強大的分析。本書中,我會詳細描述這些被每個組件支援和不支援的Excel和Access的顯著特性。也會向您展示如何利用自己的代碼來添加一些這些控制項所缺少的功能。





OWC名稱中的”Web”部分經常使人誤解。這些控制項是標準的COM控制項,並能夠在許多的控制項容器中使用,例如微軟Internet Explorer,微軟Visual Basic,微軟Visual C++,微軟Visual FoxPro和微軟Office使用者表單。然而,這些控制項的一些行為使它們尤其適合於在Internet Explorer的特殊環境中使用。例如,WEB瀏覽器為文檔提供自動的捲軸,但是人們經常會為頁面中內建一組捲軸的控制項而煩惱。試算表控制項和資料透視控制項能夠通過設定,自動調整大小來適合它們當前的內容,而不需要內部捲軸。此外,所有的控制項都支援在Internet Explorer中可用的顏色名稱,還支援數字RGB值。這就意味著您可以使用”CornSilk”或者”PapayaWhip”(我個人的愛好)元素來設定背景顏色,控制項會象Internet Explorer那樣將色彩轉換成適當的RGB值。

OWC名稱中的”Components”部分雖然比使用單詞”Controls”要準確的多(儘管在這本書中我會為了方便將OWC稱為”controls”),但是也令人相當迷惑。Office Web Components的與眾不同之處在於,他們能夠在類似web頁面,Visual Basic表單等等控制項容器中使用,也能象不可視對象那樣在記憶體中被使用。大部分的COM控制項只能在控制項容器中被用作可視控制項,而大部分的不可視對象,例如那些通過微軟ADO介面訪問的對象,只能在記憶體中使用而不能放在表單或web頁面中。OWC庫設計的目的是可以通過任何一種方式來使用。這使得您能夠通過它們暴露的使用者介面來使用這些控制項或者使用這些控制項的各種後台服務,例如試算表的重新計算功能。這種能夠以不可見對象的方式來使用的能力,也使您能夠在伺服器上用這些庫方便地產生可以在任何web瀏覽器中查看的靜態內容 (在這一章的後面會更多的講到這方面的內容)。



所有控制項都支援一組豐富的編程介面,這些介面能夠在微軟VBScript(Visual Basic的指令碼版本),微軟Jscript,微軟VBA(Visual Basic for Application),Java,C++以及任何其它能夠調用雙COM介面或調度COM介面的語言中調用。這意味這您可以將這些組件添加到定製的解決方案中,並根據您的需要設計它們的外觀和行為。我將在後續章節中討論這些組件大部分的重要屬性,方法和事件,並在這些章節中通過講述各種解決方案來講述這些重要內容中的絕大部分,這些解決方案可以在本書附贈的CD中找到。



參見

如果您正在尋找關於COM技術的權威的指南,我建議您選讀David Chappell的《Understanding ActiveX and OLE(Microsoft Press,1996)》一書。



讓我們瀏覽一下每一個組件,並討論我們能夠使用它們來建立哪些類型的解決方案。之前已經提到過了,後面的四章將會更加深入的討論每一個控制項。



工作表元件

工作表元件(如圖1-1所示)象一個Excel試算表的精簡版,由一個試算表使用者介面和一個重算引擎組成,支援Excel 2000中幾乎所有的計算功能。使用這個控制項,您可以改變和重新計算數值;排序,過濾和滾動資料;保護單元不被修改;甚至可以將資料重新裝載到Excel 2000中,以進行進一步的處理。試算表控制項能夠從傳入的參數中或從指向HTML格式的Excel試算表檔案的任何URL處裝入資料。






圖1—1 工作表元件



當您要在企業內部互連網上建立一個有效試算表模型,以便其他人能夠修改輸入值,並立刻看到重新計算的結果時,試算表控制項是很有用的。例如抵押計算機和償還進度表模型,產品收支平衡模型,和銷售趨勢預測表。

對於任何類型的交叉表或基於表格的資料輸入,尤其是當您需要使用有自動重算功能的公式時,這個控制項也是很有用的。例如成本報表,事件表和預算報表。

試算表控制項能夠將單元綁定到在頁面上的其它對象的屬性上,然後當資料來源表明屬性值改變時自動地更新單元以及和單元相關聯的其它單元。這使得可以在試算表中為一些特定的環境提供即時資料,例如股票組合。



為了實現即使當您在正在工作的試算表中編輯其它的公式或者正在為其它的單元設定格式時,試算表也能夠繼續監視新的資料並且重新計算,試算表控制項做了專門的設計。



圖表組件

圖表組件(如圖1-2所示)可以說是Excel圖表的一個精簡版,它支援Excel2000中的大部分平面圖表類型,例如Polar圖表類型。圖表組件的另一個重要的特徵是能夠立刻顯示多個圖形,從而允許您建立一個小型多重設計——換句話說,根據某一屬性變化的一系列圖形可以立刻進行比較。一個圖表可以和試算表控制項,資料透視控制項或者一個ADO的Recordset對象進行資料繫結,或者使用原始的資料來填充。當綁定到一個資料來源上時,無論何時資料來源發生變化圖表控制項都會更新。



參見

如果需要瞭解小型多重設計的威力的更多資訊,請看Edward Tufte的書《Envisioning Information (Graphics Press, 1990)》。








圖1-2 圖表組件



當需要用圖表來表示動態資料或監視對你的業務而言非常重要的元素時。圖表控制項會相當的有用。因為它提供豐富的編程模型,所以也能利用這個控制項向圖表中添加許多種效果,例如在座標軸的最大範圍上縮放和平移,根據滑鼠的位置在應用程式中動態地改變圖表的內容,或者讓使用者雙擊一個連結,轉到顯示所選擇的資料點的更多資訊的新頁面。



資料透視組件

資料透視組件(如圖1-3所示),是為了提供互動的資料報表和分析功能而設計的,它能提供Excel樞紐分析表的所有功能和各種外部資料類型。它能通過OLE DB從表格,和關聯式資料庫中提取資料,也能通過OLE DB從OLAP伺服器的cube和cube檔案中為OLAP提取資料。使用這個控制項,您能夠對資料進行各種方式的分組,切片和排序並查看,在動態資料上建立優美的報表和互動分析功能。



雖然它最適用於資料報表和資料分析解決方案,但您可以在很多任務中使用這個控制項,當被綁定到一個OLAP cube上時,資料透視控制項能夠給使用者提供一個靈活,高效的分析介面。IT機構能夠集中精力根據他們公司對資料的理解來收集和整理資料,並將資料裝入cube中,而操作這個控制項的使用者則能夠根據自己需求來對資料進行切片。






圖1-3 樞紐分析表



資料透視報表也能直接在關聯式資料庫上完成同樣的工作,因此即使您在OLAP系統上沒有投資,您也能夠使用這個控制項。然而,使用OLAP資料來源的效能總是要快的多,原因在於這項技術的本質。OLAP還有其它邏輯上的好處,我們將在第七章中探討銷售分析和報表解決方式時深入的討論它。



資料來源組件

資料來源組件(DSC)是需要從外部資料源獲得資料的控制項的骨幹架構。雖然這個控制項是不可見的,但是它被廣泛的使用於從層次(OLAP中的術語)或臨時OLAP cube中擷取和處理資料(第四章中將詳細介紹),以及在各種各樣的控制項之間建立資料關聯。既然資料來源組件和那些Internet Explorer和Visual Basic中的其它資料來源控制項一樣,支援相同的標準介面,那麼在這些環境中它就是可以互操作的。資料來源組件在Access2000的資料訪問頁特性中得到大量的使用,並且整合了許多Access報表引擎中的功能。



當其它的組件要從外部資料庫獲得資料時,幾乎都要用到資料來源組件。然而,它也支援它自己的一個編程模型,您能使用它來建立或者操作層次的Recordset對象。一般來說,您不需要過多的考慮資料來源控制項,因為其它組件和Access2000資料訪問頁設計器會為您設定和調用它。



疑問:1、The "Components" part of OWC's name is a touch confusing這句如何翻譯?

2、the PivotTable component (shown in Figure 1-3) provides all the functionality found in Excel PivotTables and external data ranges.中的external data ranges如何翻譯?





附錄:英文原文

What Are the Office Web Components?

The Office Web Components are a set of Component Object Model (COM) controls designed to bring interactive spreadsheet modeling, database reporting, and data visualization to a number of control containers. The OWC library contains four principal components: Spreadsheet, Chart, PivotTable, and Data Source. We'll discuss each of these controls briefly in this section and in much more detail in the following chapters.

NOTE


--------------------------------------------------------------------------------

COM is also known as ActiveX. I was on the Visual Basic team when Microsoft invented the term "ActiveX" to describe the COM technologies, throwing most of our customers for a loop since they had just gotten used to saying COM after we stopped using the term "OLE." Since I'm not a marketing person, I'll just use the term COM in this book to describe the Component Object Model technologies. (throw…for a loop:大吃一驚)

The word "Office" in the name "Office Web Components" indicates that the controls were developed by some of the same programmers who created Microsoft Excel and Microsoft Access and that the controls were made to look, feel, and behave like small versions of their Microsoft Office siblings. These controls definitely don't have all the features found in Excel and Access—in other words, you wouldn't want to dynamically download all of Excel and Access to view a report in your browser! However, the controls do contain many of the commonly used features, especially those needed when interacting with content that's already been created. Plus, they can read and write the HTML file format of Excel 2000, allowing the user to click a button and load the current data into Excel for more powerful analysis. In this book, I'll detail the noteworthy Excel or Access features that are and aren't supported by each component. I'll also show you how to add some of these missing features with your own code.

The "Web" part of OWC's name is often misleading. The controls are standard COM controls and can be used in many control containers such as Microsoft Internet Explorer, Microsoft Visual Basic, Microsoft Visual C++, Microsoft Visual FoxPro, or Microsoft Office UserForms. However, the controls have a few behaviors that make them especially suited to the unique environment of Internet Explorer. For example, web browsers automatically support scrolling along a document, and it's often annoying for a control in the page to have its own set of scroll bars. The Spreadsheet and PivotTable controls can be set to automatically adjust themselves to fit their current content without requiring internal scroll bars. Also, all the controls support the color names available in Internet Explorer in addition to supporting numeric RGB values. That means you can set the background color of an element to "CornSilk" or "PapayaWhip" (my personal favorite), and the control will convert the color to the appropriate RGB value just as Internet Explorer would.

The "Components" part of OWC's name is a touch confusing, although it's more accurate than using the word "Controls" (though I will often refer to OWC as "controls" for convenience throughout this book). The Office Web Components are unusual in that they can be used in control containers like web pages, Visual Basic forms, and so on, as well as in memory as invisible objects. Most COM controls can be used only as visible controls in control containers, and most invisible objects, such as those accessed via the Microsoft ActiveX Data Objects (ADO) interface, can be used only in memory and cannot be put on a form or web page. The OWC library was built so that its components could be used either way, which enables you to use the controls with the user interfaces they expose or for their base services, such as spreadsheet recalculation. The ability to use the components as invisible objects also enables you to use the library on a server to easily generate static content that users can view in any web browser (more on that later in the chapter).

All the controls support a rich set of programming interfaces that you can call from Microsoft VBScript (Visual Basic Scripting Edition), Microsoft JScript, Microsoft VBA (Visual Basic for Applications), Java, C++, and any other language capable of calling a dual or dispatch COM interface. That means you can weave the components into a custom solution and make them look and act the way you want. I will discuss most of the important properties, methods, and events in the subsequent chapters and will cover many more of these in the chapters describing the various solutions found on the companion CD.

SEE ALSO


--------------------------------------------------------------------------------

If you are looking for a definitive reference on COM, I'd recommend picking up a copy of David Chappell's Understanding ActiveX and OLE (Microsoft Press, 1996).

Let's take a brief look at each of the components and discuss what kinds of solutions you can build with them. As already mentioned, the next four chapters will cover each component in more depth.

The Spreadsheet Component

The Spreadsheet component (shown in Figure 1-1) is like a small version of an Excel spreadsheet, complete with a spreadsheet user interface and a recalculation engine that supports nearly all the calculation functions in Excel 2000. With this control, you can change or recalculate values; sort, filter, and scroll data; protect cells; and even reload the data into Excel 2000 for further manipulation. The Spreadsheet control can load its data from an embedded parameter or from any URL that points to an Excel spreadsheet saved in HTML file format.


Figure 1-1. The Spreadsheet component.

The Spreadsheet control is useful anytime you want to make a spreadsheet model available on your intranet so that others can change the input and instantly view the recalculated results. Examples include a mortgage calculator and payment schedule model, a product break-even model, and a sales forecasting model.

This control is also useful for any kind of cross-tabulated or grid-based data entry, especially when you need to use formulas with automatic recalculation. Examples include expense reports, timesheets, and budgets.

The Spreadsheet control has the ability to bind cells to properties of other objects on the page and then automatically update the cell and its dependents when the source indicates that the property value has changed. This makes it possible to feed real-time data into the spreadsheet for scenarios such as a stock portfolio.

The Spreadsheet control is specifically designed to keep listening for new values and recalculating even when you are editing other formulas or formatting other cells in the spreadsheet you're working on.

The Chart Component

The Chart component (shown in Figure 1-2) is comparable to a small version of Excel charting, supporting most of the two-dimensional chart types in Excel 2000 as well as a Polar chart type. Another big feature is that the Chart control can display many plots at once, allowing you to create a small-multiple design—in other words, a collection of plots that vary by one property and can be compared at a glance. A chart can be data-bound to the Spreadsheet control, the PivotTable control, or an ADO Recordset object, or it can be filled with literal data values. When bound to a data source, a Chart control will update whenever the source data changes.

SEE ALSO


--------------------------------------------------------------------------------

For more information on the power of small-multiple designs, see Edward Tufte's book Envisioning Information (Graphics Press, 1990).


Figure 1-2. The Chart component.

The Chart control is primarily useful any time you need to chart live data or monitor a specific metric critical to your business. Because it supports a rich programming model, you can also add many effects to a chart with this control, such as zooming and panning on large axes, dynamically changing other content in the application based on the mouse's location, or letting users double-click to link to a new page displaying more information about the selected data point.

The PivotTable Component

Designed to deliver interactive data reporting and analysis, the PivotTable component (shown in Figure 1-3) provides all the functionality found in Excel PivotTables and external data ranges. It can retrieve data from tabular, relational databases through OLE DB, as well as from OLAP server cubes and cube files through OLE DB for OLAP. Using this control, you can view data grouped, sliced, and sorted in a variety of ways, creating polished reports and interactive analysis on live data.

You can use this control for many tasks, although it's best suited for database reporting and data analysis solutions. When bound to an OLAP cube, the PivotTable control can provide the user with a flexible, high-performing analysis surface. IT groups can concentrate on collecting and cleaning data and loading it into cubes that reflect the way their company thinks about the data, while users working with this control can create slices of the data to fit their own needs.


Figure 1-3. The PivotTable component.

The PivotTable control can also perform the same operations directly on a relational database, so you can use it even if you don't have an investment in an OLAP system. However, the performance when using an OLAP data source is always much faster because of the nature of the technology. OLAP has other logical benefits that we'll discuss further when we explore the Sales Analysis and Reporting solution in Chapter 7.

The Data Source Component

The Data Source component (DSC) is the backbone for controls that require data from external sources. Although this control is invisible, it is widely used to retrieve data, manipulate data into hierarchies or temporary OLAP cubes (more on this in Chapter 4), and establish data bindings between the various controls. Since the DSC supports the same standard interfaces as other data source controls found in Internet Explorer and Visual Basic, it will interoperate in those environments. The DSC is used heavily in Access 2000's data access pages feature and encapsulates much of the functionality found in the Access reporting engine.

The DSC is involved almost any time the other components retrieve data from an external database. However, it also supports a programming model of its own, and you can use it to build or manipulate hierarchical Recordset objects. In general, you don't need to think much about the DSC since the other components and the Access 2000 Data Access Page Designer will set it up and implement it for you.


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.