Cellset 范例

目录

如下代码演示如何打开 Cellset、打印每个位置的 Members 的标题和打印 Cell 的格式化值。该代码假定在名为 Servername 的 OLAP 服务器上存在名为 Bobs Video Store 的数据源。

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
www.2mysite.net