I am using the following template for populating a table while using the xdocreport library
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
What am I doing wrong?
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