Java generates a word file based on the template. java template word
Original article: java generates word files based on templates
Source code: http://www.zuidaima.com/share/1550463664884736.htm
Steps for generating a word template by AVA
1. Copy freemarker-2.3.13.jar to the project \ WEB-INF \ lib directory
2. Edit the Template File
(1) Save the DOC file as an xml file, open the xml file in the eclipse environment, right-click and choose "Source"> "format ". Note that the xml file property is a UTF-8.
(2) Replace $ {XXX} with the content to be replaced in the xml file.
(3) copy the content of the xml file to the corresponding ftl file.
Note:
Table processing method if the template contains a table, only one header and one table row are left in the word file. Find the row location of the table in the converted xml file, "<w: tr ..." Start with, and end with "</w: tr>. Add: <# list wordBeans as w> after the table row: </# list>
The image processing method converts the image to be saved into a binary string, save it to the variable and replace the binary string in the xml file. Note that the Key value of the data stored in dataMap must correspond to the parameter in the template.
3. Run word. java
Execution result: