- 授权协议: Apache-2.0
- 开发语言: Java
- 操作系统: 跨平台
- 软件首页: https://github.com/Sayi/poi-tl
- 软件文档: http://deepoove.com/poi-tl/
软件介绍
Java word的模板引擎,对docx格式的文档增加模板语法,简化样式处理,支持对段落、页眉、页脚、表格等模板替换。
poi-tl是基于apache poi的一套拥有简洁API的跨平台的模板引擎。核心API只需要一行代码:
XWPFTemplate template = XWPFTemplate.compile("~/file.docx").render(datas);
所有的语法结构都是以 {{ 开始,以 }} 结束。
-
{{template}} 普通文本
-
{{@template}} 图片
-
{{#template}} 表格
-
{{*template}} 列表
-
{{+template}} 文档
示例
-
word中包含模板内容{{title}}
-
使用 'XWPFTemplate.compile(file).render(datas)'
-
输出到流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();
