返回或设置一个
Recordset 对象,该对象作为指定查询表的数据源。可读写。
语法
表达式.Recordset
表达式 一个代表 PivotCache 对象的变量。
说明
如果此属性用来覆盖现有记录集,更改将在运行 Refresh 方法时生效。
示例
此示例在活动工作表的 A3 单元格上,通过连接到 Microsoft Jet 上的 ADO 创建一个新的数据透视表高速缓存,然后再基于该高速缓存新建一个数据透视表。
| 示例代码 |
// Open the connection.
let cnnConn = New ADODB.Connection
cnnConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0"
cnnConn.Open "C:\\perfdate\\record.mdb"
// Set the command text.
let cmdCommand = New ADODB.Command
let cmdCommand.ActiveConnection = cnnConn
cmdCommand.CommandText = "Select Speed, Pressure, Time From DynoRun"
cmdCommand.CommandType = adCmdText
cmdCommand.Execute()
// Open the recordset.
let rstRecordset = New ADODB.Recordset
let rstRecordset.ActiveConnection = cnnConn
rstRecordset.Open(cmdCommand)
// Create a PivotTable cache and report.
let objPivotCache = ActiveWorkbook.PivotCaches.Add(xlExternal)
let objPivotCache.Recordset = rstRecordset
objPivotCache.CreatePivotTable(Range("A3"),"Performance")
let pt = ActiveSheet.PivotTables("Performance")
pt.SmallGrid = false
let pi1 = ActiveSheet.PivotTables("Performance").PivotFields("Pressure")
pi.Orientation = xlRowField
pi.Position = 1
let pi2 = ActiveSheet.PivotTables("Performance").PivotFields("Speed")
pi2.Orientation = xlColumnField
pi2.Position = 1
let pi3 = ActiveSheet.PivotTables("Performance").PivotFields("Time")
pi3.Orientation = xlDataField
pi3.Position = 1
// Close the connections and clean up.
cnnConn.Close()
cmdCommand = Nothing
rstRecordSet = Nothing
cnnConn = Nothing
}
|