Docx4j - How to replace placeholder with value

前端 未结 2 1385
轮回少年
轮回少年 2021-02-06 10:46

I\'ve been trying to work through the examples FieldMailMerge and VariableReplace but can\'t seem to get a local test case running. I\'m basically trying to start with one docx

2条回答
  •  长情又很酷
    2021-02-06 11:24

    The issue is that I was trying to create the placeholders as just plain text within the docx file. What I should've been doing instead is using the MergeField functionality within Word which I didn't fully understand and appreciate, hence the confusion. Basically I didn't know that this is what was being meant within the documentation because I'd never used it, I just assumed it was still some kind of xml text replacement.

    That being said it's still fairly difficult to find a good explanation of this Word feature. After looking at a few dozen explanations I still couldn't find a nice clean explanation of this Word feature. The best explanation I was able find can be found here. Basically you want to do Step 3.

    That being said, once I created MergeFields in Word and ran the code, it worked perfectly. The method to use is docx4jReplaceTwoPeopleTest. The problem wasn't in the code but in my understanding of how it worked within Word.

提交回复
热议问题