public class WordFillUtil {
public static void main(String[] args) {
try {
XWPFDocument document = new XWPFDocument(OPCPackage.open("path/to/your/document.docx"));
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("这是填充的内容");
public class WordTemplateFillUtil {
public static void main(String[] args) {
Configuration configuration = new Configuration(Configuration.VERSION_2_3_30);
configuration.setClassForTemplateLoading(WordTemplateFillUtil.class, "/");
try {
Template template = configuration.getTemplate("word_template.ftl");
Map<String, Object> data = new HashMap<>();
data.put("content", "这是填充的内容");