change template dynamically at run time

Hi all,
I try to create a generic template which covers different presentation situations. Suppose I have a table in database with 4 columns: fName,lName, add, favorite color. Not all the dataset cells are filled with values for each column. My docx/xls template consists of a table with 4 columns. I need to read the data from database and write it to the table but if there is no information for cell in a dataset of the table i would like to ommit the row in the table as well. I have sketched the situation and attached it to the question hoping make it clear. Is there a way in YARG to do that or shall i make two different templates?

regards
Iman

ask

Hello.

Unfortunately, YARG doesn’t have any logic to hide cells inside the single band.

Techincally, you can change you SQL query to return data in another form (as field name, field value pairs)
and change the template to output the pairs. To simplify the SQL query you can run raw select from groovy script and the convert it to list of pairs programmatically.

I hope this will help.

Since YARG uses docx4j as well, is it possible to create dynamic reports with docx4j and use YARG for converting docx to other formats? can i use them parallel?

With docx4j you can create docx and xlsx files. Then you can convert them to PDF with com.haulmont.yarg.formatters.impl.xls.PdfConverterImpl#convertToPdf method.

Do you need any other formats?

I will convert them to html too which works with YARG as well.

Right, you can convert to HTML DOCX, but not XLSX.

1 Like