forked from Sayi/poi-tl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
121 lines (100 loc) · 3.49 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/pygment_trac.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<title>poi-tl</title>
</head>
<body>
<header>
<div class="inner">
<h1>poi-tl</h1>
<h2>word模板渲染组件 ver 0.0.3</h2>
<a href="https://github.com/Sayi/poi-tl" class="button"><small>View project on</small> GitHub</a>
</div>
</header>
<div id="content-wrapper">
<div class="inner clearfix">
<section id="main-content">
<h3>概述</h3>
<p>通过对设计优雅的word模板进行渲染,方便word文档的下载、打印、报表等,即一个轻量级的word生成组件。</p>
<h3>引入</h3>
<p>将下边的依赖条件放到你项目的 maven pom.xml 文件里</p>
<pre><code><dependency>
<groupId>com.deepoove</groupId>
<artifactId>poi-tl</artifactId>
<version>0.0.3</version>
</dependency>
</code></pre>
<h3>示例</h3>
<p>模板内容:{{date}}</p>
<p>代码如下:</p>
<pre><code>//read template
XWPFTemplate doc = XWPFTemplate.create("/Users/Sayi/template.docx");
//render
RenderAPI.render(doc, new HashMap<String, Object>(){{
put("date", "2015-04-01");
}};);
//out document
FileOutputStream out = new FileOutputStream("out.docx");
doc.write(out);
out.close();
</code></pre>
<h3>语法</h3>
<p>所有的语法结构都是以 {{ 开始以 }} 结束,文档的样式继承模板标签的样式,也可以在渲染数据中指定,实现了样式的最大自由化。</p>
<p>
<ul>
<li>
<p>{{template}}</p>
<p>普通文本,渲染数据为:String或者TextRenderData</p>
</li>
<li>
<p>{{@template}}</p>
<p>图片,渲染数据为:PictureRenderData</p>
</li>
<li>
<p>{{#template}}</p>
<p>表格,渲染数据为:TableRenderData</p>
</li>
</ul>
</p>
<h3>高级:扩展</h3>
<p>
<ul>
<li>
<p>实现自定义渲染器,继承RenderPolicy接口,实现render方法</p>
<pre><code>
@Override
public void render(ElementTemplate runTemplateP, Object renderData,
XWPFTemplate template) {
RunTemplate runTemplate = (RunTemplate) runTemplateP;
XWPFRun run = runTemplate.getRun();
......
}
</code></pre>
</li>
<li><p>支持模板自定义渲染</p>
<p>通过给XWPFTemplate对象注册标签对应的渲染器,如下:
<pre><code>doc.registerPolicy("template", new MyRenderPolicy()); </code></pre></p></li>
<li><p>动态表格渲染</p>
<p>为了方便对模板中已存在的表格进行动态处理,组件自带了渲染器抽象类DynamicTableRenderPolicy,通过注册表格内的任意标签为自己的渲染器即可
</ul>
</p>
</section>
<aside id="sidebar">
<p>Deeply in love with the things you love</p>
<p`>Just deepoove.</p>
</aside>
</div>
</div>
</body>
</html>