Using repeated sections
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
Creating a repeated section in Word templates
- Create a table with at least two rows, select one row and add a rich text content control:
- Then click Properties:
- Type ReportItems into the Tag field:
- Now add other content controls inside the ReportItems content control, and specify internal column names in the Tag field:
- Now JungleDocs will copy all selected items’ Titles, Dates and Comments into the table.
This template is not associated with any list or view, so it can be used to generate reports from any list that has the right internal column names.
Important: a report will not be generated correctly if the internal column names in a list are different from the internal column names specified in the template.
Creating a repeated section in Excel templates
To get your repeated section working in Excel there are a couple of configurations you will need to set. There are also two ways to insert this section. Let's get started.
Method 1: inserting a comment
1. Add a comment with a repeater function to the top left cell of your repeater region.
2. Command 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.
Currently available commands for arg1:
- GetView("List Name"; "View Name") – this will return all items in your specified lists’ view.
- FindItems("List Name"; "Column Name"; "Value") – this will return all items from your specified list, that contain your specified value "Value" in your specified column "Column Name".
- width – optional width parameter – maximum number of columns repeater has to repeat. By default, its value is 0. It means – 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 height parameter – it means, how many rows repeater has to repeat. 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. Inside the repeater region, you can specify additional tags from repeater context. One comment can contain multiple commands. Add additional tags for columns that you need to be repeated.
4. If you want to copy list items’ values to your Excel sheet, you have to add a Repeater() command and add additional commands for every column you need to be copied:
In this example, it will 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 many items the function GetView("Tasks"; "AllItems") will return. 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: inserting a table
We could get the same result more easily by inserting a simple table.
- Insert a table:
- In the first content cell of the table, add 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.