package com.product.print.util; import cn.hutool.core.io.FileUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.config.Configure; import com.deepoove.poi.config.ConfigureBuilder; import java.io.IOException; import java.util.HashMap; import java.util.Map; /** * @Author cheng * @Date 2023/8/5 14:18 * @Desc */ public class PrintTest { static String templatePath = "d:\\desktop\\APP_NOTICE_DECIDE.docx"; static String outPath = "d:\\desktop\\APP_NOTICE_DECIDE_out.docx"; public static void main(String[] args) throws IOException { Map values = new HashMap<>(); values.put("name", "许鹏程"); ConfigureBuilder config = Configure.createDefault().builder(); JSONArray array = new JSONArray(); JSONObject object=new JSONObject(); object.put("node_uuid","flow"); object.put("node_title","node_title"); object.put("node_content","node_content"); object.put("opinion","opinion"); object.put("sign_attachment_uuid","sign_attachment_uuid"); array.add(object); config.addPlugin('@', new FlowOpinionRenderPolicy(array)); FileUtil.touch(outPath); XWPFTemplate.compile(templatePath, config.build()).render(values).writeToFile(outPath); } }