poi-tl循环表格列和行

简介: poi-tl循环表格列和行
  • 循环行


观测指标 {{rows}} 日期
[title]


  • 循环列


{{column}}观测指标 [month]
结论
// 循环行
// LoopRowTableRenderPolicy policyRow = new LoopRowTableRenderPolicy();
// Configure config = Configure.builder().bind("rows", policyCol).build();
// 循环列
LoopColumnTableRenderPolicy policyCol = new LoopColumnTableRenderPolicy();
Configure config = Configure.builder().bind("column", policyCol).build();
XWPFTemplate template = XWPFTemplate.compile(wordTemplate, config).render(
       getData(reportData, associateId)
);
private HashMap<String, Object> getData(Map<String, Object> reportData, Long enterpriseId) {
    return new HashMap<String, Object>() {{
        JSONObject json = enterpriseOperatingVisibleLightIndexService.getEnterpriseOperatingVisibleLightIndexByEnterpriseId(enterpriseId);
        // 表格
        // put("rows", row(json));
        put("column", column(json));
    }};
}
private List<Column> column(JSONObject json) {
     List<Column> list = new ArrayList<>();
     JSONArray heads = (JSONArray) json.get("head");
     for (Object j : heads) {
         Column column = new Column();
         JSONObject _j = (JSONObject) j;
         column.month =  StringUtils.toString(_j.get("reportDate"));
         list.add(column);
     }
     return list;
 }
private List<Row> row(JSONObject json) {
     List<Row> list = new ArrayList<>();
     JSONArray heads = (JSONArray) json.get("head");
     for (Object j : heads) {
         Row row = new Row();
         JSONObject _j = (JSONObject) j;
         row.title =  StringUtils.toString(_j.get("titleText"));
         list.add(row);
     }
     return list;
 }
class Row {
    String title;
}
class Column {
    String month;
}


相关文章
Springboot 导出word,动态填充表格数据
Springboot 导出word,动态填充表格数据
|
Java
Java Poi-tl操作Word文档,插入文本和图片
poi-tl(poi template language)是Word模板引擎,基于Microsoft Word模板和数据生成新的文档
1816 0
|
XML Java API
使用 XDocReport 将 .docx 文件转换为 .pdf 文件
本文介绍如何使用 XDocReport 库在 Java 中将 Word 文件转换为 PDF 文件
5754 0
java生成word(使用Poi-tl)
java生成word(使用Poi-tl)
882 0
|
11月前
|
存储 IDE Java
Java“ClassFormatError”解决
Java中的“ClassFormatError”是一个运行时异常,通常发生在类文件格式不正确或被篡改时。本文将介绍该错误的常见原因及解决方法,帮助开发者快速定位并解决问题。
441 2
|
12月前
|
Java Apache Maven
Java将word文档转换成pdf文件的方法?
【10月更文挑战第13天】Java将word文档转换成pdf文件的方法?
3580 1
|
Java Apache Maven
Java中使用poi+poi-tl实现根据模板导出word文档
这个过程不仅简化了文档生成的工作,而且保证了生成文档的一致性与准确性,特别适合于那些需要生成大量文档的自动化场景。通过以上步骤,Java开发人员可以实现高效、可靠的Word文档导出功能。
3007 0
|
Java BI API
SpringBoot + POI-TL:高效生成Word报表的技术盛宴
【8月更文挑战第22天】在日常的工作与学习中,文档处理特别是Word报表的自动生成,是许多项目中不可或缺的一环。传统的手工编辑Word文档不仅效率低下,还容易出错,特别是在需要批量生成包含动态数据的报告时,更是令人头疼不已。幸运的是,结合Spring Boot的简洁高效与POI-TL的强大功能,我们能够轻松实现Word报表的快速生成,既提升了工作效率,又保证了数据的准确性和报表的美观性。
1270 0
|
Java Apache 索引
POI操作大全(动态合并单元格,为单元格生成一个自定义的数据显示格式,自定义公式计算结果生成,读取excel,word文件在生成图片,word指定位置生成图片)
POI操作大全(动态合并单元格,为单元格生成一个自定义的数据显示格式,自定义公式计算结果生成,读取excel,word文件在生成图片,word指定位置生成图片)
721 1