请我想在嵌套循环中动态添加图像,我使用 docx 作为模板。我使用 xdocreport 1.0.2 和速度。
这是我的代码:
List<Obect> structureList=new arrayList<Object>();
HashMap<String, Object> structureMap = new HashMap<String, Object>();
for(Structure sutructure:structureList){
List<Obect> orientationList=new arrayList<Object>();
//orientation can be vertical or horizontal;
for(Orientation orientation: OrientationList){
HashMap<String, Object> orientationMap = new HashMap<String, Object>();
List<Obect> projectionList=new arrayList<Object>();
for(integer projection: projectionList){
HashMap<String, Object> projectionMap = new HashMap<String, Object>();
projectionMap.put("projectionImage", getImageproviderByOrientationAndProjection(orientation, projection);
projectionList.add(projectionMap);
}
orientationMap.put("projections", projectionList);
orientationList.add(orientationMap);
}
structureMap.put("orientation", orientationList);
structureList.add(structureMap);
}
上下文(“结构”,结构列表)
//我的元数据设置如下:
metadata.addFieldAsImage("projectionImage", "projection.projectionImage");
在我的模板(.docx)中,我这样做:
"#"foreach($structure in $structures){
"#"foreach($orientation in $structure.orientations){
"#"for($projection in $orientation.projections){
//print image by projection
}
}
}