Iterations
Overview
OpenReport allows to declare a loop and add repetitively (a set of) similar objects. The "loop" instance specifies the loop settings and adds the same block of components to the "document" fixed number of times. Loop can be set manually or can be obtained using the "source" instance.
Manual
This specification declares a loop with iterator "year" using "iterator_name" property. The "iterator_type" property specifies the method the iterator is set: "manual" or "source". With "manual" the iterator is specified manually using "iterator_values" property.
- document:
name: document.docx
structure:
- loop:
iterator_name: year
iterator_type: manual
iterator_values: [2025, 2026]
iterator_applicable:
- text:
body: Total sales for year @iterator{year} have increased.
Iterator usage
The specification above declares iterator (year) with manually specified values [2025, 2026], therefore the document will contain:
Total sales for year 2025 have increased.
Total sales for year 2026 have increased.
Source
With "source" the iterator values are an output of "source" instance. For example:
- text:
body: "The sales per month are:"
- loop:
iterator_name: sales_month_i
iterator_type: source
source:
output: array
source_type: python
python_executable: calculate_sales_per_month
iterator_applicable:
- text:
body: " - @iterator{sale_month_i} EUR"
Iterator usage
The specification above declares iterator (sales_month_i). If the script outputs [10, 20, 30], the document will contain:
The sales per month are:
- 10 EUR
- 20 EUR
- 30 EUR
Required properties
Required properties for "loop" instance is "iterator_name", "iterator_type", "iterator_applicable" and depending on "iterator_type" value either "iterator_values":
- loop:
iterator_name:
iterator_type: manual
iterator_applicable:
# ...
iterator_values:
Or "source":
- loop:
iterator_name:
iterator_type: source
iterator_applicable:
# ...
source:
# ...
Continue to Document iterations