Planification
Share your planification with Carbone
- Template type document docx simple
- Carbone min. v5.0.0+
- Features loop filter alias aggregator
- Target planification custom
Objectives
You want to generate a report to showcase your planning with the following features:
- A table with different widths between the first page and subsequent pages.
- Automatic deduction of the number of lines to display on the first page, as descriptions have varying lengths.
- Simplified syntax to create a more readable template.
- Automatic calculation of the subtotal for the displayed elements on the first page.
Solution
Here’s how you can achieve this using Carbone:
Estimate the number of characters per line
Create the first table on the first page. Since the length of descriptions varies, they may span multiple lines. To address this, estimate the number of characters that can fit on a single line (e.g., 40), based on your layout settings.
Define the number of lines each description will occupy
To determine the number of lines each description will take:
Divide the length (
len
) of the description by the estimated number of characters per line (e.g., 40).Round up to the nearest whole number using the
ceil
formatter.Store the cumulative sum (
cumSum
) using theset
formatter.The corresponding formula is as follows:
{d.steps[].description:len:div(40):ceil:cumSum:set(.nbRow)}
At this stage, each object will have a new property named nbRow
, which indicates the number of lines it will occupy based on the characteristics of the first table.
JSON Before
{
"steps": [
{
"step": 1,
"name": "Choosing the land",
"duration_days": "30",
"description": "Identify and visit several plots to assess location, viability, and utility connections. Finalize the purchase once the land is selected."
},
{...},
{
"step": 6,
"name": "Foundations",
"duration_days": "20",
"description": "Dig trenches, pour the foundations, and set up the base structure."
},
{...}
]
}
JSON After
{
"steps": [
{
"step": 1,
"name": "Choosing the land",
"duration_days": "30",
"description": "Identify and visit several plots to assess location, viability, and utility connections. Finalize the purchase once the land is selected.",
"nbRow":4
},
{...},
{
"step": 6,
"name": "Foundations",
"duration_days": "20",
"description": "Dig trenches, pour the foundations, and set up the base structure.",
"nbRow":22
},
{...}
]
}
Define and use aliases
Using aliases will make the Carbone tags more readable afterward.
Define one alias to set the filtered data for the first table, and another to set the filtered data for the second table.
{#steps =d.steps[i, nbRow < 22]}
{#steps2 = d.steps[i, nbRow > 21]}
Use
{$steps.description}
and{$steps2.description}
respectively in the tables
Compute the subtotal
To print the subtotal, use the
aggSum
formatter. You can filter the values to include only the relevant ones.{d.steps[nbRow<22].duration_days:aggSum}
And there you go!
Tips
Prevent rows from breaking across pages
If you don’t want rows to break across pages, follow these steps:
- Highlight the table in the template.
- Right-click and go to the Table Properties menu.
- Navigate to the Row section.
- Deselect the option to allow rows to break across pages.
Repeat header rows on subsequent pages
If you want to repeat the first row when your table spans page 3 and beyond, follow these steps:
- Highlight the first row of your second table in the template.
- Right-click and go to the Table Properties menu.
- Navigate to the Row section.
- Select the option "Repeat as header row at the top of each page."
Perfect!