Report

Synthèse

The Report object references a report in an ArcGIS Pro project (.aprx) file. It provides access to common properties and methods.

Discussion

An ArcGIS Pro project can contain multiple reports. Reports are accessed using the listReports method on the ArcGISProject object, and it returns a Python list of Report objects. It is important to uniquely name each report so that a specific report can be easily referenced by its name. Each report has metadata properties that can be viewed or modified.

The Report object returned using the listReports method also represents the first ReportSection. The referenceDataSource property can be modified using the setReferenceDataSource method. A definitionQuery can be applied to the first report section to filter the rows exported to PDF. The listSections method gives access to all report sections and ReportLayoutSection objects in a report.

Use the exportToPDF method to export the report to a .pdf document.

Propriétés

PropriétéExplicationType de données
definitionQuery
(Lecture et écriture)

The definition query of the first ReportSection. Use this to filter the records exported to PDF.

String
metadata
(Lecture et écriture)

Get or set the report's Metadata class information. Note that setting metadata is dependent on the isReadOnly property value.

Metadata
name
(Lecture et écriture)

The report's name. It is important that all reports in a project have a unique name so they can be easily referenced by name.

String
referenceDataSource
(Lecture seule)

The reference data source connection information of the first ReportSection.

Dictionary

Vue d’ensemble des méthodes

MéthodeExplication
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})

Exports a report to a Portable Document Format (PDF) file.

listSections ({wildcard})

Returns a Python list of ReportSection and ReportLayoutSection objects in a report.

setReferenceDataSource (data_source)

Sets a report's reference data source.

Méthodes

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})
ParamètreExplicationType de données
out_pdf

A string that represents the path and file name of the output export file.

String
page_range_type

A string that defines the type of page range to export. The default is ALL.

  • ALLExport all pages of the report.
  • LASTExport the last page of the report.
  • EVENExport the even numbered pages of the report.
  • ODDExport the odd numbered pages of the report.
  • RANGEExport the pages listed in the page_range parameter .

(La valeur par défaut est ALL)

String
page_range

A string that identifies the pages to be exported if the RANGE option in the page_range_type parameter is used (for example, 1, 3, 5-12). If any other page_range_type value is used, the page_range value will be ignored.

String
starting_page_number

Applies an offset to the page numbering to add additional pages to the beginning of the report. The default offset is 1.

(La valeur par défaut est 1)

Integer
total_page_number

The total number of pages to label, for example, when your report displays X of Y pages. This is useful when you want to combine multiple reports into one. The default is -1, which means there is no override.

(La valeur par défaut est None)

Integer
resolution

An integer that defines the resolution of the export file in dots per inch (dpi).

(La valeur par défaut est 96)

Integer
image_quality

A string that defines output image quality.

  • BESTAn output image quality resample ratio of 1
  • BETTERAn output image quality resample ratio of 2
  • NORMALAn output image quality resample ratio of 3
  • FASTERAn output image quality resample ratio of 4
  • FASTESTAn output image quality resample ratio of 5

(La valeur par défaut est BEST)

String
compress_vector_graphics

A Boolean that controls compression of vector and text portions of the output file. Image compression is defined separately.

(La valeur par défaut est True)

Boolean
image_compression

A string that defines the compression scheme used to compress image or raster data in the output file.

  • ADAPTIVEAutomatically selects the best compression type for each image on the page. JPEG will be used for large images with many unique colors. DEFLATE will be used for all other images.
  • JPEGA lossy data compression.
  • DEFLATEA lossless data compression
  • LZWLempel-Ziv-Welch, a lossless data compression
  • NONECompression is not applied
  • RLERun-length encoded compression

(La valeur par défaut est ADAPTIVE)

String
embed_fonts

A Boolean that controls the embedding of fonts in an export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed.

(La valeur par défaut est True)

Boolean
jpeg_compression_quality

A number that controls compression quality value when image_compression is set to ADAPTIVE or JPEG. The valid range is 1 through 100. A jpeg_compression_quality of 100 provides the best quality images but creates large export files. The recommended range is 70 through 90.

(La valeur par défaut est 80)

Integer

PDF files are designed to be consistently viewable and printable across platforms. They are commonly used for distributing documents on the web and are a standard interchange format for content delivery. PDF files are editable in many graphics applications and retain annotation, labeling, and attribute data for map layers. PDF exports support embedding of fonts and can display symbology correctly even if the user does not have Esri fonts installed.

listSections ({wildcard})
ParamètreExplicationType de données
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.

(La valeur par défaut est None)

String
Valeur renvoyée
Type de donnéesExplication
List

A Python list of ReportSection and ReportLayoutSection objects in a report.

Returns a Python list of ReportSection and ReportLayoutSection objects in a report.

setReferenceDataSource (data_source)
ParamètreExplicationType de données
data_source

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

(La valeur par défaut est None)

Object

The setReferenceDataSource method sets the data source that the report references using a Layer object, a Table object, or a string that represents the path to an external data source

Exemple de code

Report example 1

The following script exports a report to PDF using a page range:

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")
Report example 2

The following script changes the metadata for a report:

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()
Report example 3

The following script sets the reference data source for the first report section in a report:

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'}}
Report example 4

The following script modifies the definition query for the first report section in a report:

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'
Report example 5

The following script gets all report and report layout section objects using 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