官網地址
Poi-tl Documentationword模板引擎https://deepoove.com/poi-tl
?github 地址
https://github.com/Sayi/poi-tl/tree/master
gitcode 加速地址
GitCode - 全球開發者的開源社區,開源代碼托管平臺GitCode是面向全球開發者的開源社區,包括原創博客,開源代碼托管,代碼協作,項目管理等。與開發者社區互動,提升您的研發效率和質量。https://gitcode.com/gh_mirrors/po/poi-tl/tree/master
Maven依賴
<dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>1.12.2</version>
</dependency>
使用場景
官方文檔 有很多示例,這里就不展示里
場景一
文字指定填充
?
代碼;
@GetMapping("/simple")public ResponseEntity simpleDemo() throws Exception{try(InputStream is = new ClassPathResource("/templates/template.docx").getInputStream();FileOutputStream os = new FileOutputStream("templates/output/template-out.docx")) {XWPFTemplate template = XWPFTemplate.compile(is).render(new HashMap<String, Object>(){{put("filename", "錄取通知書");put("姓名", "祖安蒙多");put("學院", "地面戰斗學院");put("專業名稱", "地面炮灰");put("大學名稱", "火星殖民大學");}});template.writeAndClose(os);}return ResponseEntity.ok().build();}