Java export pdf report three: the use of poi-tl - text template

Earlier, I introduced to you the specific requirements to be realized and some ideas and simple processes for choosing the realization method during the realization process. In this article, I will introduce to you some confusions encountered in the specific use of poi-tl and subsequent solutions.

First of all, we need to understand poi-tl. The picture below is taken from the introduction of poi-tl on github.

Its open source project is on github, you can go to github to view the specific introduction, poi-tl

For its help documentation, please refer to: poi-tl Chinese help documentation

First of all, we need to introduce the pot-tl jar package in pom.xml

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

Then refer to the help documentation and we start to make our word template

It is configured as a variable in the place that needs to be dynamically generated in the word template, the format is { {var}}, var is the variable name

In the java code, we can directly add the corresponding variables and values ​​to the data model

Map<String, Object> reportDatas = new HashMap<String, Object>();
reportDatas.put("name","张三");       
reportDatas.put("guardian","张大");       
reportDatas.put("birthday","1985.09.08");
reportDatas.put("sex","男");
……

Text templates are the most commonly used templates, and it is recommended to use text templates as much as possible. First, it is easy to use, and second, it can maintain the style of your template well.

Guess you like

Origin blog.csdn.net/wzl19870309/article/details/103435114