时尚女装网站设计,河北建设工程造价信息网站,怎么做vip电影网站,怎样在网上推广先看模板和导出的效果 模板 效果 根据模板循环生成表格#xff0c;每个表格再循环填充数据#xff0c;也就是两层循环#xff0c;第一层循环是学生学期信息#xff0c;第二层循环是学生的成绩数据。
第一个循环
{{?listTable}}
{{/}}第二个循环
{{reportList}}
表格…先看模板和导出的效果 模板 效果 根据模板循环生成表格每个表格再循环填充数据也就是两层循环第一层循环是学生学期信息第二层循环是学生的成绩数据。
第一个循环
{{?listTable}}
{{/}}第二个循环
{{reportList}}
表格中[]是具体的属性比如[displayName]表示课程名称核心代码
maven
dependencygroupIdcom.deepoove/groupIdartifactIdpoi-tl/artifactIdversion1.10.5/version
/dependencyTest
public void export() throws IOException {// 模板文件ClassPathResource classPathResource new ClassPathResource(/doc/template.docx);InputStream inputStream classPathResource.getInputStream();MapString, Object map new HashMap();String str FileUtil.readFileByPath(C:\\Users\\chenggaowei\\Desktop\\score.json);ListStudentCourseVO studentList new ArrayList();// 模拟写入多个学生的数据for (int i 0; i 3; i) {StudentCourseVO vo new StudentCourseVO();vo.setStudentName(张三 (i 1));vo.setPeriodName(2023-2024学年上学期);ListReportField reportList JSONObject.parseArray(str, ReportField.class);vo.setReportList(reportList);studentList.add(vo);}// 循环的数据listTable和模板对应map.put(listTable, studentList);LoopRowTableRenderPolicy policy new LoopRowTableRenderPolicy();// reportList和模板对应Configure config Configure.builder().bind(reportList, policy).build();XWPFTemplate template XWPFTemplate.compile(inputStream, config).render(map);File outputFile FileUtil.createTempFile(out.docx);template.writeToFile(outputFile.getAbsolutePath());FileUtil.openFolder(outputFile);}学业课程数据vo /*** 学业课程数据* author chenggaowei* date 2023/10/8*/
Data
public class StudentCourseVO {/*** 学生id*/private String studentId;/*** 学生姓名*/private String studentName;/*** 学期id*/private String periodId;/*** 学期名称*/private String periodName;/*** 成绩数据*/private ListReportField reportList;
}