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
|