ReportTable 对象 (Project)

表示窗体的项目报告中的表中的一个形状。

备注

注意

[!注释] 宏录制 ReportTable对象未实现。 也就是说, Project在录制一个宏并手动添加报告表或编辑表元素,不会记录添加和操作报表的步骤。

ReportTable对象是一种 Shape对象;它与 Table对象无关。 项目具有有限的 VBA 支持报告表;若要指定的表字段,您以手动方式使用 字段列表任务窗格 (请参见图 1)。 若要显示或隐藏 字段列表任务窗格,请在 表格工具下的 设计选项卡在功能区中选择 表格数据命令。 若要指定的表格布局或设计属性,可以在功能区中使用 设计选项卡和 布局选项卡。

您可以更新数据的查询与报表的表中,通过使用 UpdateTableData 方法。 若要获取某个表格单元格的文本,使用 GetCellText 方法。

若要以编程方式创建 ReportTable,使用 Shapes.AddTable 方法。 若要返回 ReportTable 对象,请使用 Shapes(Index).Table,其中 Index 是形状的名称或索引号。

示例

TestReportTable宏创建一个报告,名为表测试,然后创建一个 ReportTable对象。

Sub TestReportTable()
    Dim theReport As Report
    Dim theShape As Shape
    Dim theReportTable As ReportTable
    Dim reportName As String
    Dim tableName As String
    Dim rows As Integer, columns As Integer, left As Integer, _
        top As Integer, width As Integer, height As Integer    
    rows = 3
    columns = 4
    left = 20
    top = 20
    width = 200
    height = 100
    
    reportName = "Table Tests"
    tableName = "Basic Project Data Table"
    
    Set theReport = ActiveProject.Reports.Add(reportName)
    
    ' Project ignores the NumRows and NumColumns parameters when creating a ReportTable.
    Set theShape = theReport.Shapes.AddTable( _
        rows, columns, left, top, width, height)
    
    theShape.Name = tableName
    
    Set theReportTable = theShape.Table
    
    With theReportTable
        Debug.Print "Rows: " & .RowsCount
        Debug.Print "Columns: " & .ColumnsCount
        Debug.Print "Table contents:" & vbCrLf & .GetCellText(1, 1)
    End With
End Sub

在图 1 中,由 TestReportTable宏创建表测试报告中顶级的 ReportTable对象。 首次创建表时,它有一行和一列; AddTable方法的 NumRowsNumColumns参数不起作用。 从“ 字段列表 ”任务窗格手动向表添加字段时,或使用 UpdateTableData 方法时,将更新表中的行数和列数。 您可以筛选字段以限制的行数。 TestReportTable宏的 VBE 立即窗口中写入以下︰

Rows: 1
Columns: 1
Table contents:
Use the Table Data taskpane to build a table

在图 1 的底部 ReportTable对象是项目创建 报表工具下的 设计选项卡上选择 时的默认报告表。 它显示的项目名称、 开始日期、 完成日期和百分比完成的项目的摘要任务 (任务 ID = 0)。

图 1. ReportTable 对象需要手动编辑才能添加字段和更改格式

ReportTable 对象需要手动编辑若要删除 ReportTable 对象,请使用 Shape.Delete 方法,如以下宏中所示:

Sub DeleteTheReportTable()
    Dim theReport As Report
    Dim theShape As Shape
    Dim reportName As String
    Dim tableName As String
    
    reportName = "Table Tests"
    tableName = "Basic Project Data Table"
    
    Set theReport = ActiveProject.Reports(reportName)
    Set theShape = theReport.Shapes(tableName)
    
    theShape.Delete
End Sub

若要删除整个报告,改为其他视图,如下所示的以下宏︰

Sub DeleteTheReport()
    Dim i As Integer
    Dim reportName As String
    
    reportName = "Table Tests"
    
    ' To delete the active report, change to another view.
    ViewApplyEx Name:="&Gantt Chart"
    
    ActiveProject.Reports(reportName).Delete
End Sub

方法

名称
GetCellText
UpdateTableData

属性

名称
ColumnsCount
RowsCount

另请参阅

报表对象

形状对象

图表对象

Chart.DataTable 属性

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。