ReportSection

摘要

ReportSection 对象引用报表中的报表部分。 它可提供对常见属性(例如定义查询)的访问权限以及设置参考数据源的方法。

说明

ArcGIS Pro 报表可以包含多个报表部分。 可使用 Report 对象上的 listSections 方法访问报表部分。 这将返回 ReportSectionReportLayoutSection 对象的 Python 列表。 可通过唯一 name 引用每个报表部分,并且每个部分都具有 REPORT_SECTION type

ReportSection 具有可使用 referenceDataSource 属性识别的数据源。 要更改数据源,使用 setReferenceDataSource 方法。 该方法可将新数据源中的字段映射到原始数据源定义的报表字段。 字段名称(非字段别名)必须为区分大小写的精确匹配。

要过滤导出为 PDF 的记录,修改报表部分的 definitionQuery 属性。 要从导出的 PDF 中排除报表部分,将 visible 属性设置为 false

属性

属性说明数据类型
definitionQuery
(可读写)

第一个 ReportSection 的定义查询。 使用此项可过滤导出至 PDF 的记录。

String
metadata
(可读写)

获取或设置报表的元数据类信息。 请注意,设置元数据取决于 isReadOnly 属性值。

Metadata
name
(可读写)

报表的名称。 有必要确保工程中的所有报表都具有唯一的名称,因为这样便可通过这些唯一名称轻松对其进行引用。

String
referenceDataSource
(只读)

第一个 ReportSection 的参考数据源连接信息。

Dictionary

方法概述

方法说明
setReferenceDataSource (data_source)

设置报表部分的参考数据源。

方法

setReferenceDataSource (data_source)
参数说明数据类型
data_source

The data reference for the report section. This parameter can be a Layer object, a Table object, or a string that represents the path to an external data source.

(默认值为 None)

Object

setReferenceDataSource 方法可以使用 Layer 对象、Table 对象或表示外部数据源路径的字符串来设置报表部分参考的数据源。

代码示例

ReportSection 示例 1

以下脚本用于获取报表中的所有报表部分:

aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\NationalParks.aprx")
report = aprx.listReports("National Parks Report")[0]
sections = [s.name for s in report.listSections() if s.type=="REPORT_SECTION"] # Get list of report section names
for s in sections:
	print(s)
# National Parks Overview
# Park Highlights
# Annual Review
ReportSection 示例 2

以下脚本用于将报表部分可见性设置为 False

aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\NationalParks.aprx")
report = aprx.listReports("National Parks Report")[0]
section = report.listSections("National Parks Overview")[0] # Find the report section by name
section.visible = False
ReportSection 示例 3

以下脚本用于将报表中第二个报表部分的参考数据源设置为地图中的表:

aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\NationalParks.aprx")
map = aprx.listMaps("National Parks")[0]  # Find a map in the project
table = map.listTables()[0] # Find the first table in the map
report = aprx.listReports("National Parks Report")[0]
section = report.listSections()[1] # Find the report section by index
section.setReferenceDataSource(table)
ReportSection 示例 4

以下脚本用于修改报表中第三个报表部分的定义查询:

aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\NationalParks.aprx")
report = aprx.listReports("National Parks Report")[0]
section = report.listSections("Annual Review")[0] # Find the report section by name
section.definitionQuery = "ParkName = 'Yosemite'"