Figure 3 Office Web Components (version 10)
| 組件 |
描述 |
| PivotTable |
使使用者串連到支援 OLE DB Provider for OLAP Services 8.0 或更高版的 OLAP 資料來源上 (也可串連到 Excel 電子資料工作表單 和 SQL Server 、 Access 關聯式資料庫)。PivotTable 控制項允許使用者對資料進行透視、分組、篩選和排序等操作。 |
| Spreadsheet |
提供電子資料工作表單使用者介面,包括重算引擎和擴充函數庫。 |
| Chart |
圖形化顯示來自某個綁定資料來源、PivotTable 或 Spreadsheet 控制項的資料。當 Chart 組件被綁定到 PivotTable 控制項且使用者重新透視資料時能自動重新整理。 |
| DataSource |
管理與後台資料庫伺服器的通訊。PivotTable 和 Spreadsheet 組件實際上能單獨串連到資料來源,,不一定非得要 DataSource 組件。這是因為其 XML 資料可以直接包含 OLE DB 串連串。 |
Figure 4 PivotTable and Chart-related Objects
| 成員 |
描述 |
| PivotTable |
使使用者串連到支援 OLE DB Provider for OLAP Services 8.0 或更高版的 OLAP 資料來源上 (也可串連到 Excel 電子資料工作表單 和 SQL Server 、 Access 關聯式資料庫)。PivotTable 控制項允許使用者對資料進行透視、分組、篩選和排序等操作。 |
| PivotView |
表示 PivotTable 的一個特定視圖. 用於對 PivotTable 視圖中的行、列、尺規、格式化進行設定。 |
| PivotDataAxis |
包含與資料軸相關的方法和屬性 |
| PivotResultColumnAxis |
包含與列軸相關的方法和屬性 |
| PivotResultRowAxis |
包含與行軸相關的方法和屬性 |
| PivotFieldSet |
Cube中定義的欄位集 |
| PivotField |
Cube中定義的欄位 |
| ChartSpace |
使使用者串連到支援 OLE DB Provider for OLAP Services 8.0 或更高版的任何 OLAP 資料來源上,(也可串連到 Excel 電子資料工作表單和 SQL Server、Access 關聯式資料庫)。ChartSpace 允許使用者圖形化顯示資料並且將控制項綁定到一個已存在的 PivotTable 或 Spreadsheet。 |
| ChCharts |
ChChart 對象集合 |
| ChChart |
ChartSpace 中的單個圖表,一個ChartSpace 可容納多達64個圖表。 |
Figure 5 PivotTable Component's Programmatic Interface
| 成員 |
類型 |
描述 |
| ActiveView |
屬性 |
表示一個活動的 PivotTable 布局。該屬性返回一個 PivotView 對象。 |
| ColumnAxis |
屬性 |
表示列軸中的欄位。返回一個 PivotAxis 對象。 |
| ConnectionString |
屬性 |
設定串連到 Analysis Services 伺服器的連接字串,ConnectionString 屬性中的 DataSource 參數決定了 OWC 組件將要使用的連線協定。 |
| DataAxis |
屬性 |
表示資料軸的規模。返回一個 PivotAxis 對象。 |
| DataMember |
屬性 |
設定控制項將要從 Analysis Services 請求的資料來源名稱。它與Cube同名。 |
| IncludedMembers |
屬性 |
定義了 PivotField 內的資料成員。該屬性接受的參數為單一成員或成員數組。 |
| IsIncluded |
屬性 |
設定所包含的欄位並啟用 PivotFieldSet。 |
| RowAxis |
屬性 |
表示行軸中的欄位,返回 PivotAxis 對象。 |
| XMLData |
屬性 |
設定或返回當前用於 PivotTable 報表控制項的 XML 資料。有關報表的細節 (格式和資料) 均儲存在 XML 資料中。也包括了 OLAP 串連詳細資料。 |
| AddCustomGroupField |
方法 |
為指定的 PivotFieldSet 添加一個定製的分組欄位。 |
| AddCustomGroupMember |
方法 |
為指定的 PivotFieldSet 添加一個定製的分組成員。 |
| InsertFieldSet |
方法 |
在行或列軸中插入一個欄位集。 |
| CommandExecute |
事件 |
在某個命令執行之後觸發,ChartCommandIdEnum 和PivotCommandId 常量包含用於每個 OWC 組件所支援的命令清單。 |
| Query |
事件 |
PivotTable 啟用某個查詢時觸發。 |
Figure 6 Chart Component's Programmatic Interface
| 成員 |
類型 |
描述 |
| DataSource |
屬性 |
為 Chart 控制項定義資料來源。當設定另一個控制項(如:PivotTable 或 Spreadsheet)這樣有效地綁定 Chart 控制項到其它控制項。 |
| Type |
屬性 |
象 ChartChartTypeEnum 枚舉所定義的那樣定義圖表類型,預設類型為橫條圖。 |
Figure 8 Connecting to an OLAP Data Source
function initializePivotTable(strDataMember) {// This function calls the InitializePivotTableXML() Web// methodvar iCallID = service.svcOLAP.callService(onInitializePivotTableResult,'InitializePivotTableXML',strDataMember);}function onInitializePivotTableResult(result) {// This function handles the InitializePivotTableXML()// Web method resulttext = result.value; // result string// Evaluate return resultif (!result.error) {// Assign the XML to the PivotList XMLData valuefrm1.PivotTable1.XMLData = text;}else {alert("Unhandled error - " + result.errorDetail.code +" " + result.errorDetail.string);}}Figure 9 Generate XMLData for a PivotTable Control
<WebMethod()> Public Function InitializePivotTableXML(ByVal _strDataMember As String) As StringDim m_XML As StringDim strOLAPConn As String = _ConfigurationSettings.AppSettings("OLAPConnectionString")TryDim objPT As PivotTableClass = New PivotTableClassobjPT.ConnectionString = strOLAPConnobjPT.DataMember = strDataMemberm_XML = objPT.XMLDataobjPT = NothingCatch err As Exceptionm_XML = "<err>" & err.Source & " - " & err.Message & _"</err>"FinallyEnd TryReturn (m_XML)End FunctionFigure 10 LoadCustomPivotTableReport Web Method
<WebMethod()> Public Function LoadCustomPivotTableReport(ByVal _strCity1 As String, ByVal strCity2 As String) As StringDim m_XML As StringDim strOLAPConn As String = _ConfigurationSettings.AppSettings("OLAPConnectionString")Dim objPT As PivotTableClass = New PivotTableClassDim objPTView As PivotViewDim fldCity, fldName, fldProdFamily As PivotFieldDim fSetCustomers, fSetProduct As PivotFieldSetTryobjPT.ConnectionString = strOLAPConnobjPT.DataMember = "Sales"objPT.AllowFiltering = FalseobjPTView = objPT.ActiveViewobjPTView.TitleBar.Caption = "City Comparison of DrinkSales"' Define the column elementsobjPTView.ColumnAxis.InsertFieldSet(objPTView.FieldSets("Time"))objPTView.ColumnAxis.FieldSets("Time").Fields("Year").Expanded = True' Define the row elementsfSetCustomers = objPTView.FieldSets("Customers")objPTView.RowAxis.InsertFieldSet(fSetCustomers)fSetCustomers.Fields("Country").IsIncluded = FalsefSetCustomers.Fields("State Province").IsIncluded = FalsefSetCustomers.Fields("Name").IsIncluded = False' Define the members of the row elementsfldCity = fSetCustomers.Fields("City")fldCity.IncludedMembers = New Object() {strCity1, strCity2}' Exclude all other field row members in the fieldsetfSetProduct = objPTView.FieldSets("Product")objPTView.RowAxis.InsertFieldSet(fSetProduct)fSetProduct.Fields("Product Department").IsIncluded = FalsefSetProduct.Fields("Product Category").IsIncluded = FalsefSetProduct.Fields("Product Subcategory").IsIncluded =FalsefSetProduct.Fields("Brand Name").IsIncluded = FalsefSetProduct.Fields("Product Name").IsIncluded = FalsefldProdFamily = fSetProduct.Fields("Product Family")fldProdFamily.IncludedMembers = "Drink"' Define the measuresobjPTView.DataAxis.InsertTotal(objPTView.Totals("Store Sales"))objPTView.DataAxis.Totals("Store Sales").NumberFormat = _"Currency"' Return the XML data to the client side scriptm_XML = objPT.XMLDataobjPT = NothingCatch err As Exceptionm_XML = "<err>" & err.Source & " - " & err.Message & "</err>"FinallyEnd TryReturn (m_XML)End FunctionFigure 11 Load the XMLData for a Custom Report
function LoadSavedReport() {// Purpose: Call Web Service method to load the saved// reportvar iCallID = service.svcOLAP.callService(onLoadSavedReportResult,'LoadSavedReport', 'OLAPReport1.xml');}function onLoadSavedReportResult(result) {// Purpose: This function handles the// wsOLAP.onLoadSavedReportResult() Web Service resultvar text = result.value; // result string// Evaluate return resultif (!result.error) {// Assign the XML to the PivotList XMLData valuefrm1.PivotTable1.XMLData = text;}}Figure 12 JavaScript and VBScript Event Handler
<script language="javascript" event="Query" for="PivotTable1">{var sLog = document.Form1.Text1.value + "";document.Form1.Text1.value = "Query Event Fired. " + sLog;}</script><script language="vbscript">Sub PivotTable1_CommandExecute(Command, Succeeded)Dim ptConstantsSet ptConstants = document.Form1.PivotTable1.Constants' Check to see if the PivotTable list has been' refreshed.If Command = ptConstants.plCommandRefresh Then' Write the current data and time to the text box.document.Form1.Text1.value = vbCrLf & _"PivotTable Last Refreshed on " & Date & " at " _& Time & vbCrLf & document.Form1.Text1.valueEnd IfEnd Sub</script>Figure 13 Creating Custom Groups
<WebMethod()> Public Function ApplyCustomGrouping(ByVal _strReportXMLData As String) As StringDim m_xml As StringDim objPT As PivotTableClass = New PivotTableClassDim objPTView As PivotViewDim fsTime As PivotFieldSetDim fsHalfYear As PivotFieldTryobjPT.XMLData = strReportXMLDataobjPTView = objPT.ActiveView' Set a variable to the Time field set.fsTime = objPTView.FieldSets("Time")' Add a custom group field named "Group1" to the Time field' set.fsHalfYear = fsTime.AddCustomGroupField("CustomGroup1", _"CustomGroup1", "Quarter")' Add a custom field set member. This member includes all' "Q1" and "Q2" members under 1997.fsHalfYear.AddCustomGroupMember _(fsTime.Member.ChildMembers("1997").Name, _New Object() {"Q1", "Q2"}, "1stHalf")' Add another custom fieldset member to include all "Q3"' and "Q4" members under 1997.fsHalfYear.AddCustomGroupMember _(fsTime.Member.ChildMembers("1997").Name, _New Object() {"Q3", "Q4"}, "2ndHalf")' Collapse the fieldset at the custom member levelfsHalfYear.Expanded = Falsem_xml = objPT.XMLDataobjPT = NothingCatch err As Exceptionm_xml = "<err>" & err.Source & " - " & err.Message & _"</err>"FinallyEnd TryReturn (m_xml)End Function