输入模板
注:集合使用{{xx}}进行标识(在其需要循环的上一行进行标识),[xx]中的内容表示集合中对象属性
public static void main(String[] args) throws IOException {
Map<String, Object> map = new HashMap<>();
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
// 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
Configure configure = Configure.builder().bind("bz", policy).build();
List<TestLoopRowTable> forms = new ArrayList<>();
forms.add(new TestLoopRowTable("济南","f1","s1","f2","s2","f3","s3","f4","s4","f5","s5"));
forms.add(new TestLoopRowTable("青岛","f1","s1","f2","s2","f3","s3","f4","s4","f5","s5"));
map.put("bz",forms);
File file = new File("D:\\文件输入.docx");
XWPFTemplate template = XWPFTemplate.compile(file,configure).render(map);
FileOutputStream out = new FileOutputStream(new File("D:\\文件输出.docx"));
template.write(out);
out.flush();
out.close();
template.close();
}