word文件格式:
jar包:
<dependency>
<groupId>com.deepoove</groupId>
<artifactId>poi-tl</artifactId>
<version>1.10.0</version>
</dependency>
样例代码:
// 封装参数集合
Map<String, Object> data = new HashMap<String, Object>() {{
put("date", DateUtil.format("yyyy年MM月dd日", new Date()));
}};
try (InputStream is = new ClassPathResource("file/path/fileName.docx").getInputStream()) {
ConfigureBuilder builder = Configure.builder();
XWPFTemplate template = XWPFTemplate.compile(is, builder.build()).render(data);
String wordPath = "E:\\newFileName.docx";
template.writeAndClose(Files.newOutputStream(Paths.get(wordPath)));
} catch (IOException e) {
throw new RuntimeException(e);
}