Populating tables with templates in xdocreport

3.1k Views Asked by At

I am using the following template for populating a table while using the xdocreport library enter image description here

The Java code that I am using is given below:

            InputStream in = GenerateStakeholderReport.class.getResourceAsStream( "StakeholderReport_Template.docx" );
        IXDocReport report = XDocReportRegistry.getRegistry().loadReport( in, TemplateEngineKind.Velocity );
        FieldsMetadata metadata = report.createFieldsMetadata();
        metadata.load( "stakeholders", StakeHolder.class, true );
        IContext context = report.createContext();
        Project project = new Project( "Project 1", "A project for Oragisational Change",
                                       "System Implementation", "Bob Yardley","Peter");
        context.put( "project", project );
        List<StakeHolder> stakeholders = new ArrayList<StakeHolder>();
        stakeholders.add( new StakeHolder( "01", "External", "President", "Head Quarter", "High", "5000", "Key Infulencer" ) );
        stakeholders.add( new StakeHolder( "02", "Internal", "CEO", "Head Quarter", "High", "2500", "Key Infulencer"  ) );
        context.put( "stakeholders", stakeholders );
        OutputStream out = new FileOutputStream( new File( "StakeHolderReport_Out.docx" ) );
        report.process( context, out );

The output that I am getting is not what I expected; the table rows are are not populated (there should have been 2 rows). Also, two of the column headings are not getting displayed

enter image description here

What am I doing wrong?

2

There are 2 best solutions below

0
On

Try prepending @before-row to the first MergeField, before #foreach... and @after-row to the last one, before #end.

See this: https://github.com/opensagres/xdocreport/wiki/ODTReportingJavaMainListFieldAdvancedTable

0
On

You put foreach inside a column. You must put in line.

  1. Remove foreach and end of first column.
  2. Create a line between header and body of the table.
  3. Put the foreach code in this line. --> #foreach($s in stakeholders)
  4. Create a line in footer of table and put the "end" there. ---> #end