对应依赖
<repositories>
   <!-- 使用 Free Spire.Doc for Java 的jar包实现替换word中的内容-->
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.cn/repository/maven-public/</url>
    </repository>
</repositories>
    
<dependencies>
	<dependency>
	    <groupId>e-iceblue</groupId>
	    <artifactId>spire.doc.free</artifactId>
	    <version>5.2.0</version>
	</dependency>
</dependencies>
代码示例
public static void main(String[] args) throws IOException {
     String infile = "E:\\jiarg\\Documents\伙食费签报件模板.doc";
     String outfile = "E:\\jiarg\\Documents\\伙食费签报件(输出).doc";
     Map<String, String> map = new HashMap<String, String>();
     map.put("${czsp}", "处长审批意见...");
     map.put("${fgcwsp}", "分管财务审批...");
     map.put("${fgldsp}", "业务分管领导...");
    
     Document document = new Document();
     // 载入Word文档
     document.loadFromFile(infile );
     // 将替换模式设置为:仅替换第一个匹配项
     document.setReplaceFirst(true);
     // 匹配替换文档内容
     for (Map.Entry<String, String> entry : map.entrySet()) {
         document.replace(entry.getKey(), entry.getValue(), false, true);
     }
     // 保存结果文档
     document.saveToFile(outfile);
 }
运行效果
模板样式
 
 替换结果
 



















