前言:poi模板语言(poi-tl)是基于Microsoft Word模板和数据生成新文档的Word模板引擎。文件中的任何地方做任何事都是poi-tl的星辰大海。有关详细的使用方法,请参阅Poi-tl Documentation
1、引入依赖性。
Dependency
GroupIdcom.deepoove/groupId
工件dpoi-TL/工件id
版本1.8.2/版本
/dependency2,准备Word模板
文本标签:{{}}
图片标记:以@开头:{{@var}}
自我介绍。docx
3、主要代码。
import Java . io . file;
Import java.u
Import java.u
import Java . io . fileoutputstream;
Import com.dee
Import com.dee
Import com.dee
Public class应用程序{
public static void main(string[]args)throws exception {
MapString,Object map=new hash map();
Map.put('name ',' Tony ');
Map.put('age ',' 18 ');
//读取本地磁盘图片
Map.put ('wechatpicture ',new picturerenderdata (100、100、' d: \ \ WEC));
通过//URL读取web图片
Map.put ('picture ',new picturerenderdata (200,400,')。png ',by(';));
File file=new File('D:\\自我介绍。docx ');
xwpf template template=xwp ftem(file)。render(贴图);
file output stream out=new file output stream(new file(' d : \ \输出自我介绍)。docx '));
(out);
out . flush();
out . close();
();
}
}4、效果图
输出自我介绍。docx
路很远,那个维修很远,我要上下下搜查。
翻译:在追求真理方面,前面的路还很长,但我会百折不挠,全力追求和探索。
如果你有好的想法或方法,欢迎评论留言。一起讨论吧~