export
汇总
Report 对象将引用 ArcGIS Pro 工程 (.aprx) 文件中的 报表 。 它用于对常见属性和方法进行访问。
讨论
ArcGIS Pro 工程可包含多个报表。 可以使用 createReport 方法创建报表,并使用 ArcGISProject 对象上的 listReports 方法访问报表。 listReports 方法返回 Report 对象的 Python 列表。 有必要确保每个报表均具有唯一名称,因为这样可以通过其 name 轻松引用特定报表。 所有报表都具有可以查看或修改的 metadata 属性。 可以使用 pageInfo 属性访问页面信息,包括页面单位、宽度、高度和边距。
使用 listReports 方法返回的 Report 对象还表示第一个 ReportSection 。 可以使用 setReferenceDataSource 方法修改 referenceDataSource 属性。 可以将 definitionQuery 应用于第一个报表部分以过滤导出为 PDF 的行。 可使用 listSections 方法访问所有报表部分以及报表中的 ReportLayoutSection 对象。
可以使用 exportToPDF 方法将报表导出为 .pdf 文档。
语法
export()
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
definitionQuery (读取和写入) |
第一个 ReportSection 的定义查询。 使用此项可过滤导出至 PDF 的记录。 |
String |
|
metadata (读取和写入) |
获取或设置报表的 元数据 类信息。 请注意,设置元数据取决于 |
Metadata |
|
name (读取和写入) |
报表的名称。 有必要确保工程中的所有报表都具有唯一的名称,因为这样便可通过这些唯一名称轻松对其进行引用。 |
String |
|
pageInfo (只读) |
报表页面宽度、高度、单位和边距。 字段的键定义如下:
|
Dictionary |
|
referenceDataSource (只读) |
第一个 ReportSection 的参考数据源连接信息。 字段的键定义如下:
|
Dictionary |
方法
export(export_format, {report_export_options}, {display_options})
export 方法可使用指定 export_format 导出 Report ,还可以选择性地使用不同的 report_export_options 或 display_options 。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
export_format |
The supported export format object is |
Object |
|
report_export_options (可选) |
The |
Object |
|
display_options (可选) |
The |
Object |
exportToPDF(out_pdf, {page_range_type}, {page_range}, {starting_page_number}, {total_page_number}, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {jpeg_compression_quality})
用于将报表导出为便携式文档格式 (PDF) 文件。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_pdf |
用于表示输出导出文件的路径和文件名的字符串。 |
String |
|
page_range_type (可选) |
用于定义要导出的页面范围类型的字符串。 默认值为 ALL。
(默认值为 ALL) |
String |
|
page_range (可选) |
如果使用 |
String |
|
starting_page_number (可选) |
将偏移应用于页面编号以在报表开始处添加附加页面。 默认偏移为 1。 (默认值为 1) |
Integer |
|
total_page_number (可选) |
要标注的总页面数,例如,如果报表显示第 X 页,共 Y 页。 这在将多个报表合并为一个报表时将非常有用。 默认值为 -1,表示没有覆盖。 (默认值为 None) |
Integer |
|
resolution (可选) |
用于定义导出文件分辨率的整数值,单位为每英寸点数 (dpi)。 (默认值为 96) |
Integer |
|
image_quality (可选) |
定义输出图像质量的字符串。
(默认值为 BEST) |
String |
|
compress_vector_graphics (可选) |
用于控制输出文件的矢量和文本部分压缩的布尔值。 图像压缩单独定义。 (默认值为 True) |
Boolean |
|
image_compression (可选) |
用于定义在输出文件中压缩图像或栅格数据时使用的压缩方案的字符串。
(默认值为 ADAPTIVE) |
String |
|
embed_fonts (可选) |
用于控制导出文件中的字体嵌入的布尔值。 当在未安装所需字体的计算机上查看文档时,可通过字体嵌入正确显示文本和字符标记。 (默认值为 True) |
Boolean |
|
jpeg_compression_quality (可选) |
当 (默认值为 80) |
Integer |
getDefinition(cim_version)
获取报表的 CIM 定义。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
cim_version |
A string that represents the major version of the CIM. |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
返回 |
listSections({wildcard})
返回报表中 ReportSection 和 ReportLayoutSection 对象的 Python 列表。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
wildcard (可选) |
A wildcard is based on the section name and is not case sensitive. A combination of asterisks (*) and characters can be used to help limit the resulting list. (默认值为 None) |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
List |
报表中 ReportSection 和 ReportLayoutSection 对象的 Python 列表。 |
openView()
在应用程序中打开并激活一个新的报表视图窗格。
setDefinition(definition_object)
设置报表的 CIM 定义。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
definition_object |
A modified CIM definition object originally retrieved using |
Object |
setReferenceDataSource(data_source)
设置报表的参考数据源。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
data_source |
支持报表的数据参考。此参数可以为 (默认值为 None) |
Object |
updatePageInfo(pageInfo)
更新报表页面信息。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
pageInfo |
The keys for the dictionary are defined as follows:
|
Dictionary |
代码示例
以下脚本用于使用页面范围将报表导出为 PDF:
aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\USA_States.aprx")
report = aprx.listReports("Cities Report")[0] # Find report by name
report.exportToPDF(r"C:\DemoData\CitiesReport.pdf", page_range="2-10")
以下脚本用于更改报表的元数据:
aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\USA_States.aprx")
report = aprx.listReports("States Report")[1] # Find second report by name
md = report.metadata # Get report metadata
md.title = "Modified States Report"
md.save()
以下脚本用于设置报表中第一个报表部分的参考数据源:
aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\USA_States.aprx")
report = aprx.listReports("Counties Report")[0] # Find report by name, this also returns the first report section
report.setReferenceDataSource(r"C:\DemoData\USA_States.gdb\Counties")
print(report.referenceDataSource)
#{'dataset':'counties', 'workspace_factory':'File Geodatabase',
# 'connection_info':{'database':'C:\\DemoData\\USA_States.gdb'}}
以下脚本用于修改报表中第一个报表部分的定义查询:
aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\USA_States.aprx")
report = aprx.listReports()[2] # Find the third report in the project
print(report.name)
# State Population Report
report.definitionQuery = "STATE_NAME = 'California'"
print(report.definitionQuery)
# STATE_NAME = 'California'
以下脚本使用 listSections 获取所有报表和报表布局部分对象:
aprx = arcpy.mp.ArcGISProject('current') # Run this from the Python window in Pro
report = aprx.listReports("Complete Report")[0] # Find report by name
sections = report.listSections() # Get all report and report layout sections in a report
for s in sections:
print(f"Section Name: {s.name} Section Type: {s.type}")
# Section Name: Cover Page Section Type: REPORT_LAYOUT_SECTION
# Section Name: Cities Section Type: REPORT_SECTION
# Section Name: States Section Type: REPORT_SECTION
以下脚本更改文本元素的报表定义:
aprx = arcpy.mp.ArcGISProject(r'C:\projects\WaterSupply.aprx')
report = aprx.listReports('Suppliers')[0] # Find the report by name
df = report.getDefinition('V3') # Get the current CIM definition of the report
report_section = df.elements[0] # Find the first report section in the CIM
report_header = report_section.elements[4] # Find the report header subsection
title_text = report_header.elements[3] # Find the title text element
symbol = title_text.graphic.symbol.symbol # Get the text symbol
symbol.fontFamilyName = "Arial" # Change the font
report.setDefinition(df) # Set the new CIM definition
以下脚本创建一个报表并打开一个新视图:
aprx = arcpy.mp.ArcGISProject('current') # This must be run in the application
map = aprx.listMaps('TaxLots')[0] # Find the map by name
# Define report properties
ds = map.listTables('Owners')[0] # Find the data source table by name
pi = {'width': 297, 'height': 420, 'units': 'MILLIMETER', 'margins': 'WIDE'} # Define page info
f = [{'fieldName': 'Name', 'sortInfo': 'DESC', 'groupField': False},
{'fieldName': 'Address', 'sortInfo': 'ASC', 'groupField': False},
{'fieldName': 'Status', 'sortInfo': 'None', 'groupField': False}] # Define fields
s = [] # Pass no statistics
report = aprx.createReport(
page_info = pi,
data_source = ds,
fields = f,
statistics = s,
name = 'Owners') # Create the report
report_view = report.openView() # Open a new report view
以下脚本获取报表的页面信息:
aprx = arcpy.mp.ArcGISProject('current') # This must be run in the application
map = aprx.listMaps('TaxLots')[0] # Find the map by name
# Define report properties
ds = map.listTables('Owners')[0] # Find the data source table by name
pi = {'width': 297, 'height': 420, 'units': 'MILLIMETER', 'margins': 'WIDE'} # Define page info
f = [{'fieldName': 'Name', 'sortInfo': 'DESC', 'groupField': False},
{'fieldName': 'Address', 'sortInfo': 'ASC', 'groupField': False},
{'fieldName': 'Status', 'sortInfo': 'None', 'groupField': False}] # Define fields
s = [] # Pass no statistics
report = aprx.createReport(
page_info = pi,
data_source = ds,
fields = f,
statistics = s,
name = 'Owners') # Create the report
report_view = report.openView() # Open a new report view