java ~ word模板填充字符后输出到指定目录

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);
	}
相关推荐
i小杨12 分钟前
python 项目相关
开发语言·python
zh_xuan13 分钟前
kotlin定义函数和变量
android·开发语言·kotlin
CoderCodingNo14 分钟前
【GESP】C++五级真题(贪心思想考点) luogu-P11960 [GESP202503 五级] 平均分配
开发语言·c++·算法
Caarlossss20 分钟前
mybatis
java·数据库·tomcat·maven·mybatis·mybatis-spring
喵手22 分钟前
项目实战案例:从设计到部署!
java·部署·项目实战·设计
weixin_4624462325 分钟前
使用 Tornado + systemd 搭建图片静态服务(imgserver)
开发语言·python·tornado
源码获取_wx:Fegn089526 分钟前
基于springboot + vue小区人脸识别门禁系统
java·开发语言·vue.js·spring boot·后端·spring
别多香了31 分钟前
python基础之面向对象&异常捕获
开发语言·python
youngee1131 分钟前
hot100-61电话号码的字母组合
java·数据结构·leetcode
春蕾夏荷_72829772532 分钟前
Qt 命令行工具
开发语言·qt