如下代碼演示如何打開 Cellset、打印每個(gè)位置的 Members 的標(biāo)題和打印 Cell 的格式化值。該代碼假定在名為 Servername 的 OLAP 服務(wù)器上存在名為 Bobs Video Store 的數(shù)據(jù)源。
Dim cat As New ADOMD.Catalog
Dim cst As New ADOMD.Cellset
Dim axs As ADOMD.Axis
Dim I As Integer
Dim j As Integer
cat.ActiveConnection = "Data Source=Servername;" + _
"Initial Catalog=Bobs Video Store;Provider=msolap;"
cst.Source = "SELECT [Product Category].MEMBERS ON ROWS," + _
"[Store State].MEMBERS ON COLUMNS" + _
"FROM [Bobs Video Store]" + _
"WHERE ([Quantity])"
Set cst.ActiveConnection = cat.ActiveConnection
cst.Open
For i = 0 To cst.Axes(0).Positions.Count - 1
Debug.Print cst.Axes(0).Positions(i).Members(0).Caption & " ";
Set axs = cst.Axes(1)
For j = 0 To axs.Positions.Count - 1
Debug.Print " " & axs.Positions(j).Members(0).Caption & _
" " & cst(i, j).FormattedValue
Next
Next
cst.Close