poi-tl(poi-template-language)
Word 模板引擎,基于Apache POI - the Java API for Microsoft Documents。
What is poi-tl
FreeMarker、Velocity基于文本模板和数据生成新的HTML页面、配置文件等,poi-tl是Word模板引擎,基于Microsoft Word模板和数据生成新的文档。
Word模板拥有丰富的样式,poi-tl在生成的文档中会完美保留模板中的样式,还可以为标签设置样式,标签的样式会被应用到替换后的文本上,因此你可以专注于模板设计。
poi-tl是一种 "logic-less" 模板引擎,没有复杂的控制结构和变量赋值,只有标签,一些标签可以被替换为文本、图片、表格等,一些标签会隐藏某些文档内容,而另一些标签则会将一系列文档内容循环渲染。
"Powerful" constructs like variable assignment or conditional statements make it easy to modify the look of an application within the template system exclusively... however, at the cost of separation, turning the templates themselves into part of the application logic.
poi-tl支持自定义渲染函数(插件),函数可以在Word模板的任何位置执行,在文档的任何地方做任何事情(Do Anything Anywhere)是poi-tl的星辰大海。
Maven
com.deepoove
poi-tl
1.8.2
2分钟快速入门
从一个超级简单的例子开始:把{ {title}}替换成"poi-tl 模板引擎"。
新建文档模板template.docx,包含标签{ {title}}
TDO模式:Template + data-model = output
//核心API采用了极简设计,只需要一行代码
XWPFTemplate.compile("template.docx").render(new HashMap(){ {
put("title", "poi-tl 模板引擎");
}}).writeToFile("out_template.docx");
打开out_template.docx文档吧