0

请我想在嵌套循环中动态添加图像,我使用 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

           }
       }
   }
4

1 回答 1

0

使用示例中描述的 POJO (DeveloperWithImage.java)

/* Load the photos as list in the metadata */
FieldsMetadata metadata = report.createFieldsMetadata();
metadata.load( "photos", Photo.class, true );
report.setFieldsMetadata(metadata);

List<Photo> photos = ...
context.put( "photos", photos );

Photo.java:

public class Photo {
private IImageProvider photo;

@FieldMetadata( images = { @ImageMetadata( name = "photo" ) }, description="Photo"  )
public IImageProvider getPhoto() {
    return photo;
}

public void setPhoto(IImageProvider photo) {
    this.photo = photo;
}}
于 2020-07-25T04:30:01.233 回答