Hi, I am looking for java codes to generate a word document based on a word template, basically, I have a word template created and in my local path, the template has a proper format with some fields which will be filled in after java codes ran. The java codes will fetch one record from a table, and open the word template and then fill the fields in the word template, and created a new word document and save it in another folder.
I found this example: http://dev-notes.com/code.php?q=10 which is similar except it uses xml template instead of word template, can anybody show me how to make it work to change the template from xml to word (docx) template?
Thanks a lot for any help,
Ulf Dittmer wrote:This may not help you, but if this was my problem, I'd use RTF files as the templates. I think they'd be easier to manipulate, and can then be opened by any word processor afterwards.
thanks a lot, if the RTF works for my request, then I also can use it, as long as it works, I appreciate if you can provide any good working examples of using RTF, thanks again.
I don't have example code around, but if you save your templates as RTF and open it in a text editor, you'll see any template variables (like INVOICENUMBER) you have used. Using "sed" or some Java text processing library it would be straightforward to replace those with their actual values.