Using repeated sections
Applies to JungleDocs for SharePoint 2010-2019.
For a similar tutorial for JungleDocs for Office 365, click here.
Repeated sections allow you to import multiple items from a list into a document template. Therefore, they are key to creating reports with JungleDocs. Using repeated sections, you can import not only selected items, but also a filtered or unfiltered view, or a whole list.
In this tutorial, you will learn how to:
- create repeated sections in Word templates
- create repeated sections in Excel templates
Create a repeated section in a Word template
1. Create a table with at least two rows and select the seconds row (the first one will be used for titles). On the Developer tab, click the Rich Text Content Control button.
Note: to enable the Developer tab, click File > Options > Customize Ribbon, then check the Developer box and click OK.
2. Click Properties. In a pop-up window, in the Tag field, enter the ReportItems function and click OK. The selected row now becomes a repeated section. i.e, it will be repeated as many times as there are selected items when you run a JungleDocs rule.
Note: we recommend to copy and paste the Tag field value into the Title field. This way, you will be able to see the Tag field value without opening content control properties.
4. Add other content controls inside the ReportItems content control, and specify internal column names in the Tag field. In the example, the template is configured to retrieve the Title and Date column values for the selected SharePoint list items. For example, if you select three items, three rows will be created. Note that on the lower left cell a placeholder text is entered for reference. When a document is generated, the placeholder text is replaced by the column value.
Important: internal column names in the list and in the template must match, otherwise a report will not be generated correctly.
Create a repeated section in an Excel template
There are two ways to insert a repeated section in an Excel template.
Method 1: insert a comment
1. Right-click on the top-left cell and click Insert Comment.
2. Add a comment with the Repeater function.
The available syntaxes are:
- =Repeater(arg1; width; height)
- =Repeater(arg1; width)
- arg1 – command that returns a list of items, it should be a command that links your Excel template to specific data fields in your SharePoint sites.
The Repeater function supports the following arguments:
- arg1 Required. Any function that returns a set of items (e.g., GetView(), FindItems(), ReportItems()), for example:
- GetView("List Name"; "View Name") returns all items in your specified list view.
- FindItems("List Name"; "Column Name"; "Value") returns all items from your specified list that contain Value in your specified column "Column Name".
- width Optional. Maximum number of columns to be repeated. By default, its value is 0. It means that all columns will be copied in a row to the right from the current cell. For example, setting the width to 1 will only allow one (the first one) column to be repeated.
- height Optional. Maximum number of rows to be repeated. For example, setting the height to 2 will repeat 2 rows in the Excel sheet for every list entry in your SharePoint. By default, its value is 1.
3. If you want to copy list item values to your Excel sheet, you have to add the Repeater() command and add additional commands for every column you need to be copied:
In the example, a template is configured to repeat a region with a width of 6 columns, and 1 row for every list item, starting from A1 cell. It will repeat as many times as there are items the function GetView("Tasks"; "AllItems") returns. In each top cell, A1, A2, etc., we will put repeated items’ IDs. In the lower cells, B1, B2, etc., we will put repeated items’ column names, for example, Title.
Note: JungleDocs does not currently support multiple repeaters (matrix tables) on the same Excel sheet.
Method 2: insert a table
We could get the same result more easily by inserting a simple table.
1. Select cell A1 or A2. Then, on the ribbon, click Insert > Table.
2. Right-click the first content cell of the table and click Insert Comment. Enter the following comment: =Repeater(GetView("Tasks"; "AllItems")). Do not change the column title, JungleDocs will copy column titles from SharePoint automatically. JungleDocs will extend this table to contain all columns from the view and will create as many rows as it is necessary to fill with items from the view.