程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> Programming Microsoft Office 2000 Web Components第一

Programming Microsoft Office 2000 Web Components第一

編輯:.NET實例教程

第一章第二節 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.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved