Dynamic resize

Templater's low level API has the Resize(int) method which is used to (usually vertically) resize on object.
For a table that would mean adding new rows, for a list that would mean adding new list items, for a page that would mean adding new pages, etc.
While Templater could have another method Stretch(int) which could be used on a table to add new columns, that would imply that it's slowly becoming a wrapper around objects in specific formats.
Another solution is to implement stretching in specific format implementations which understand some data types and act accordingly.

So the basic idea is that some specific data types can be used to achieve adding new columns to table. Specific data type are passed through the ITemplater.Replace(tag, object) method and not the ITemplateDocument.Process(object) method.
In .NET this data types are DataTable and two dimensional array, in Java they are ResultSet and two dimensional array.

How to use this and what to expect?

  • In word, create a table with desired style and a single row and column.
  • Add a tag (for example [[DynamicTable]]) inside.
  • Pass ResultSet to it using the low level API Replace("DynamicTable", resultSet), or as a property in the high level API named DynamicTable.

When Templater starts processing ResultSet it will split that table by number of columns in ResultSet and populate and resize it accordingly by data in ResultSet.
ResultSet (Java) and DataTable (.NET) have another feature available – they can populate table headers with column names. They will do that if tag contains header metadata. In our case tag would look like [[DynamicTable]:header].

Example: Dynamic table

The following image shows a screenshot of a MS Word document, that is used for processing by Templater. Dynamic table before

Once the document is processed, myArr tag will be replaced with corresponding data, as shown in the next picture.

Dynamic table after


Example: ResultSet column generate

This example shows a screenshot of a MS Excel template, that is used for ResultSet processing. Coffees tag is placed in Table3 table, and will later be replaced with ResultSet object. ResultSet column generate before


The following picture shows a result of this example. Coffees tag is replaced with ResultSet values. Also, additional columns are added, and headers are generated from ResultSet attribute names.

ResultSet column generate after



Back to Features

t