当前位置: 首页 > news >正文

word模板内容替换

1.pom引入依赖:

<dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.0.5</version>
</dependency>
<dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>1.10.5</version>
</dependency>

2.写工具类

package  *****;import com.deepoove.poi.XWPFTemplate;import java.io.FileOutputStream;
import java.io.IOException;public class GenerateWordUtils {/**** @param path 文件模板路径* @param fileName 生成的文件名* @param param 需要替换的对象*/public static String generateWord(String path,String fileName,Object param) {try {XWPFTemplate template = XWPFTemplate.compile(path).render(param);template.writeAndClose(new FileOutputStream(fileName));} catch (IOException e) {e.printStackTrace();}return fileName;}
}

3.调用

例子:

//相对路径在项目根目录
String path = GenerateWordUtils.generateWord(new String(模板路径path.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8), 文件名fileName, 需替换的结果集resultMap);
//项目路径
String projectPath=System.getProperty("user.dir");
//文件真实路径
String realPath = projectPath+File.separator+path

http://www.lryc.cn/news/365102.html

相关文章:

  • docker安装和使用
  • 【AIGC X UML 落地】通过多智能体实现自然语言绘制UML图
  • C++访问越界
  • MATLAB format
  • Face Forgery Detection by 3D Decomposition
  • socket网络编程——多进程、多线程处理并发
  • C++---模板进阶(非类型模板参数,模板的特化,模板分离编译)
  • 锂电池寿命预测 | Matlab基于SSA-SVR麻雀优化支持向量回归的锂离子电池剩余寿命预测
  • 整理好了!2024年最常见 20 道 Kafka面试题(十)
  • Paper Survey——3DGS-SLAM
  • 搜索与图论:深度优先搜索
  • AMD显卡和英伟达显卡哪个好?
  • 5.31.8 学习深度特征以实现判别定位
  • uniapp小程序多线程 Worker 实战【2024】
  • C语言基础——数组(2)
  • 封装PHP用于发送GET和POST请求的公共方法
  • MongoDB~基础知识记录
  • DSP28335模块配置模板系列——ADC配置模板
  • 字符串转换为字节数组、16进制转换为base64、base64转换为字符串数组、base64转换为16进制(微信小程序)
  • c++中, 直接写浮点数, 是float 还是 double?
  • C++核心编程友元的应用
  • C#,JavaScript实现浮点数格式化自动保留合适的小数位数
  • Android基础-工程目录结构说明
  • 浅谈提示词发展现状,Prompt 自动优化是未来。
  • 揭秘智能测径仪省钱之道!每年能为每条产线省上百万!
  • echaerts图例自动滚动并隐藏翻页按钮
  • OpenCV的小部件最基本范例
  • 内置类型知多少?
  • 【C++题解】1090 - 同因查找
  • uni微信小程序editor富文本组件如何插入图片