Java Word 的模板引擎 poi-tl

码农软件 · 软件分类 · 模板引擎 · 2019-08-22 18:44:08

软件介绍

Java word的模板引擎,对docx格式的文档增加模板语法,简化样式处理,支持对段落、页眉、页脚、表格等模板替换。

poi-tl是基于apache poi的一套拥有简洁API的跨平台的模板引擎。核心API只需要一行代码:

XWPFTemplate template = XWPFTemplate.compile("~/file.docx").render(datas);

所有的语法结构都是以 {{ 开始,以 }} 结束。

  • {{template}} 普通文本

  • {{@template}} 图片

  • {{#template}} 表格

  • {{*template}} 列表

  • {{+template}} 文档

示例

  1. word中包含模板内容{{title}}

  2. 使用 'XWPFTemplate.compile(file).render(datas)'

  3. 输出到流OutputStream

//一行代码
XWPFTemplate template = XWPFTemplate.compile("~/template.docx").render(new HashMap(){{
        put("title", "Pil-tl 模板引擎");
}});
FileOutputStream out = new FileOutputStream("out_template.docx");
template.write(out);
out.flush();
out.close();
template.close();

本文地址:https://codercto.com/soft/d/12943.html

Web Analytics

Web Analytics

Avinash Kaushik / Sybex / 2007-6-5 / USD 29.99

在线阅读本书 Written by an in-the-trenches practitioner, this step-by-step guide shows you how to implement a successful Web analytics strategy. Web analytics expert Avinash Kaushik, in his thought-p......一起来看看 《Web Analytics》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换