ngs-doo / TemplaterExamples

Creating reports in .NET and Java
https://templater.info
The Unlicense
48 stars 27 forks source link

Word template that uses the same data in a chart and across multiple pages #37

Closed polvoblanco closed 3 years ago

polvoblanco commented 3 years ago

Hi,

Is it possible to supply Templater with a single collection of data, e.g.:

[{"type": "something" "collection": [{"data": "data" ...} ...] "count": 2} {"type": "something else" "collection": [{"other data": "other data" ...} ...] "count": 4} ... ]

Then have this data shown in a pie chart on the first page, using the "type" and "count" and then a page for each, showing the "type" as a header and the "collection" in a table?

Originally I was hoping that we could get away without the "count" and use Excel to count the records in the collection, but Excel wouldn't allow that (is that possible?)

Ideally I don't want to change the data structure unless it's not possible to achieve via the template. I have attached a test docx and json (renamed .txt as GitHub won't allow json uploads), please note the attribute names are slightly different, I changed them above to make the intention clearer.

test.docx test.txt

Regards,

Paul

zapov commented 3 years ago

You can do it via new navigation plugin. There is builtin at(index) for the first part, and you will have to implement your own for the second part, eg: skip(index)

There is a relevant example here: https://github.com/ngs-doo/TemplaterExamples/tree/master/Intermediate/LimitPlugins

polvoblanco commented 3 years ago

Thanks, however I think I explained what I was trying to do very badly. Basically I want to use the entire collection in a chart on the first page and then have a page for every record in the collection (each record contains a further collection of data that will be shown in a table).

zapov commented 3 years ago

You can still use the navigation for that purpose, but primarily to give it a different alias. Templater considers different paths as different data sources, so if you do even a useless navigation alias it will allow you to reuse the same collection in a different context