OWC简介及其属性
轉載:[url]http://www.cnblogs.com/yiriqing/archive/2006/06/14/425923.html[/url] Figure 3 Office Web Components (version 10)
Figure 4 PivotTable and Chart-related Objects
Figure 5 PivotTable Component's Programmatic Interface
Figure 6 Chart Component's Programmatic Interface
Figure 8 Connecting to an OLAP Data Source
function initializePivotTable(strDataMember) { // This function calls the InitializePivotTableXML() Web // method var iCallID = service.svcOLAP.callService (onInitializePivotTableResult, 'InitializePivotTableXML', strDataMember); } function onInitializePivotTableResult(result) { // This function handles the InitializePivotTableXML() // Web method result text = result.value; // result string // Evaluate return result if (!result.error) { // Assign the XML to the PivotList XMLData value frm1.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 String Dim m_XML As String Dim strOLAPConn As String = _ ConfigurationSettings.AppSettings("OLAPConnectionString") Try Dim objPT As PivotTableClass = New PivotTableClass objPT.ConnectionString = strOLAPConn objPT.DataMember = strDataMember m_XML = objPT.XMLData objPT = Nothing Catch err As Exception m_XML = "<err>" & err.Source & " - " & err.Message & _ "</err>" Finally End Try Return (m_XML) End Function
Figure 10 LoadCustomPivotTableReport Web Method
<WebMethod()> Public Function LoadCustomPivotTableReport(ByVal _ strCity1 As String, ByVal strCity2 As String) As String Dim m_XML As String Dim strOLAPConn As String = _ ConfigurationSettings.AppSettings("OLAPConnectionString") Dim objPT As PivotTableClass = New PivotTableClass Dim objPTView As PivotView Dim fldCity, fldName, fldProdFamily As PivotField Dim fSetCustomers, fSetProduct As PivotFieldSet Try objPT.ConnectionString = strOLAPConn objPT.DataMember = "Sales" objPT.AllowFiltering = False objPTView = objPT.ActiveView objPTView.TitleBar.Caption = "City Comparison of Drink Sales" ' Define the column elements objPTView.ColumnAxis.InsertFieldSet(objPTView.FieldSets("Time")) objPTView.ColumnAxis.FieldSets("Time").Fields("Year").Expanded = True ' Define the row elements fSetCustomers = objPTView.FieldSets("Customers") objPTView.RowAxis.InsertFieldSet(fSetCustomers) fSetCustomers.Fields("Country").IsIncluded = False fSetCustomers.Fields("State Province").IsIncluded = False fSetCustomers.Fields("Name").IsIncluded = False ' Define the members of the row elements fldCity = fSetCustomers.Fields("City") fldCity.IncludedMembers = New Object() {strCity1, strCity2} ' Exclude all other field row members in the fieldset fSetProduct = objPTView.FieldSets("Product") objPTView.RowAxis.InsertFieldSet(fSetProduct) fSetProduct.Fields("Product Department").IsIncluded = False fSetProduct.Fields("Product Category").IsIncluded = False fSetProduct.Fields("Product Subcategory").IsIncluded =False fSetProduct.Fields("Brand Name").IsIncluded = False fSetProduct.Fields("Product Name").IsIncluded = False fldProdFamily = fSetProduct.Fields("Product Family") fldProdFamily.IncludedMembers = "Drink" ' Define the measures objPTView.DataAxis.InsertTotal(objPTView.Totals("Store Sales")) objPTView.DataAxis.Totals("Store Sales").NumberFormat = _ "Currency" ' Return the XML data to the client side script m_XML = objPT.XMLData objPT = Nothing Catch err As Exception m_XML = "<err>" & err.Source & " - " & err.Message & "</err>" Finally End Try Return (m_XML) End Function
Figure 11 Load the XMLData for a Custom Report
function LoadSavedReport() { // Purpose: Call Web Service method to load the saved // report var iCallID = service.svcOLAP.callService(onLoadSavedReportResult, 'LoadSavedReport', 'OLAPReport1.xml'); } function onLoadSavedReportResult(result) { // Purpose: This function handles the // wsOLAP.onLoadSavedReportResult() Web Service result var text = result.value; // result string // Evaluate return result if (!result.error) { // Assign the XML to the PivotList XMLData value frm1.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 ptConstants Set 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.value End If End Sub </script>
Figure 13 Creating Custom Groups
<WebMethod()> Public Function ApplyCustomGrouping(ByVal _ strReportXMLData As String) As String Dim m_xml As String Dim objPT As PivotTableClass = New PivotTableClass Dim objPTView As PivotView Dim fsTime As PivotFieldSet Dim fsHalfYear As PivotField Try objPT.XMLData = strReportXMLData objPTView = 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 level fsHalfYear.Expanded = False m_xml = objPT.XMLData objPT = Nothing Catch err As Exception m_xml = "<err>" & err.Source & " - " & err.Message & _ "</err>" Finally End Try Return (m_xml) End Function
| 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 | 多維數據集中定義的字段集 |
| PivotField | 多維數據集中定義的字段 |
| 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 請求的數據源名稱。它與多維數據集同名。 |
| 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 // method var iCallID = service.svcOLAP.callService (onInitializePivotTableResult, 'InitializePivotTableXML', strDataMember); } function onInitializePivotTableResult(result) { // This function handles the InitializePivotTableXML() // Web method result text = result.value; // result string // Evaluate return result if (!result.error) { // Assign the XML to the PivotList XMLData value frm1.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 String Dim m_XML As String Dim strOLAPConn As String = _ ConfigurationSettings.AppSettings("OLAPConnectionString") Try Dim objPT As PivotTableClass = New PivotTableClass objPT.ConnectionString = strOLAPConn objPT.DataMember = strDataMember m_XML = objPT.XMLData objPT = Nothing Catch err As Exception m_XML = "<err>" & err.Source & " - " & err.Message & _ "</err>" Finally End Try Return (m_XML) End Function
Figure 10 LoadCustomPivotTableReport Web Method
<WebMethod()> Public Function LoadCustomPivotTableReport(ByVal _ strCity1 As String, ByVal strCity2 As String) As String Dim m_XML As String Dim strOLAPConn As String = _ ConfigurationSettings.AppSettings("OLAPConnectionString") Dim objPT As PivotTableClass = New PivotTableClass Dim objPTView As PivotView Dim fldCity, fldName, fldProdFamily As PivotField Dim fSetCustomers, fSetProduct As PivotFieldSet Try objPT.ConnectionString = strOLAPConn objPT.DataMember = "Sales" objPT.AllowFiltering = False objPTView = objPT.ActiveView objPTView.TitleBar.Caption = "City Comparison of Drink Sales" ' Define the column elements objPTView.ColumnAxis.InsertFieldSet(objPTView.FieldSets("Time")) objPTView.ColumnAxis.FieldSets("Time").Fields("Year").Expanded = True ' Define the row elements fSetCustomers = objPTView.FieldSets("Customers") objPTView.RowAxis.InsertFieldSet(fSetCustomers) fSetCustomers.Fields("Country").IsIncluded = False fSetCustomers.Fields("State Province").IsIncluded = False fSetCustomers.Fields("Name").IsIncluded = False ' Define the members of the row elements fldCity = fSetCustomers.Fields("City") fldCity.IncludedMembers = New Object() {strCity1, strCity2} ' Exclude all other field row members in the fieldset fSetProduct = objPTView.FieldSets("Product") objPTView.RowAxis.InsertFieldSet(fSetProduct) fSetProduct.Fields("Product Department").IsIncluded = False fSetProduct.Fields("Product Category").IsIncluded = False fSetProduct.Fields("Product Subcategory").IsIncluded =False fSetProduct.Fields("Brand Name").IsIncluded = False fSetProduct.Fields("Product Name").IsIncluded = False fldProdFamily = fSetProduct.Fields("Product Family") fldProdFamily.IncludedMembers = "Drink" ' Define the measures objPTView.DataAxis.InsertTotal(objPTView.Totals("Store Sales")) objPTView.DataAxis.Totals("Store Sales").NumberFormat = _ "Currency" ' Return the XML data to the client side script m_XML = objPT.XMLData objPT = Nothing Catch err As Exception m_XML = "<err>" & err.Source & " - " & err.Message & "</err>" Finally End Try Return (m_XML) End Function
Figure 11 Load the XMLData for a Custom Report
function LoadSavedReport() { // Purpose: Call Web Service method to load the saved // report var iCallID = service.svcOLAP.callService(onLoadSavedReportResult, 'LoadSavedReport', 'OLAPReport1.xml'); } function onLoadSavedReportResult(result) { // Purpose: This function handles the // wsOLAP.onLoadSavedReportResult() Web Service result var text = result.value; // result string // Evaluate return result if (!result.error) { // Assign the XML to the PivotList XMLData value frm1.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 ptConstants Set 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.value End If End Sub </script>
Figure 13 Creating Custom Groups
<WebMethod()> Public Function ApplyCustomGrouping(ByVal _ strReportXMLData As String) As String Dim m_xml As String Dim objPT As PivotTableClass = New PivotTableClass Dim objPTView As PivotView Dim fsTime As PivotFieldSet Dim fsHalfYear As PivotField Try objPT.XMLData = strReportXMLData objPTView = 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 level fsHalfYear.Expanded = False m_xml = objPT.XMLData objPT = Nothing Catch err As Exception m_xml = "<err>" & err.Source & " - " & err.Message & _ "</err>" Finally End Try Return (m_xml) End Function
轉載于:https://blog.51cto.com/recoverypeak/145324
總結
- 上一篇: Windows 2003 server
- 下一篇: 从宏观经济状况看目前股市