Git Product home page Git Product logo

poi-tl's Introduction

Poi-tl(Poi-template-language)

Build Status jdk1.6+ jdk1.8 poi3.16%2B poi4.0.0 Gitter

📝 Word 模板引擎,基于Apache Poi,目标是在文档的任何地方做任何事情(Do Anything Anywhere)。

下表对一些处理Word的解决方案作了一些比较:

方案 跨平台 样式处理 易用性
Poi-tl 纯Java组件,跨平台 ✅ 不需要编码,模板即样式 ✅ 简单:模板引擎,对POI进行封装,支持Word文档合并、表格处理等
Apache POI 纯Java组件,跨平台 编码 简单,没有模板引擎功能
Freemarker XML操作,跨平台 复杂,需要理解XML结构,基于XML构造模板
OpenOffice 需要安装OpenOffice软件 编码 复杂,需要了解OpenOffice的API
Jacob、winlib Windows平台 编码 复杂,不推荐使用

Maven

<dependency>
  <groupId>com.deepoove</groupId>
  <artifactId>poi-tl</artifactId>
  <version>1.5.0</version>
</dependency>

2分钟快速入门

从一个超级简单的例子开始:把{{title}}替换成"Poi-tl 模板引擎"。

  1. 新建文档template.docx,包含文本{{title}}
  2. TDO模式:Template + data-model = output
//核心API采用了极简设计,只需要一行代码
XWPFTemplate template = XWPFTemplate.compile("~/template.docx").render(new HashMap<String, Object>(){{
        put("title", "Poi-tl 模板引擎");
}});
FileOutputStream out = new FileOutputStream("out_template.docx");
template.write(out);
out.flush();
out.close();
template.close();

详细文档与示例

poi-tl中文文档 or English-tutorial Wiki

关于Apache POI的使用,这里有个入门教程:Apache POI Word(docx) 入门示例教程,更多的示例以及所有示例的源码参见JUnit单元测试。

架构设计

模板和插件构建了整个Poi-tl的核心。 Poi-tl通过极简的架构实现了模板功能并且支持最大的扩展性,架包体积仅有几十KB。

整体设计采用了Template + data-model = output模式,Configure提供了模板配置功能,比如语法配置和插件配置,Visitor提供了模板解析功能,RenderPolicy是渲染策略扩展点,Render模块提供了RenderDataCompute表达式计算扩展点,通过RenderPolicy对每个标签进行渲染。

建议和完善

参见常见问题,欢迎在GitHub Issue中提问和交流。

社区交流讨论群:Gitter频道

poi-tl's People

Contributors

dra-cula avatar jolongriver avatar sayi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.