Java generates a word file based on the template. java template word

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.