Aspose.words Java-based template generates plain text content for Word

Source: Internet
Author: User

One, create a Word template

1. Create a new Word document

2. Set the fields for four parameters respectively

(1) Position the mouse where you want to set the field

(2) Setting the domain name

(3) After setting up as shown

Second, the project

1, introducing Maven dependency

<Dependency>            <groupId>Com.aspose</groupId>            <Artifactid>Aspose-words</Artifactid>            <version>18.5</version>            <classifier>Jdk16</classifier>        </Dependency>

2. Load the authorization file

 Public Static BooleanGetlicense () {Booleanresult =false; Try{InputStream is= Asposetowordtest.class. getClassLoader (). getResourceAsStream ("License-word.xml"); License Aposelic=NewLicense ();            Aposelic.setlicense (IS); Result=true; } Catch(Exception e) {e.printstacktrace (); }        returnresult; }

3, get the value and insert into the template and generate a new document

 Public Static voidMain (string[] args)throwsException {//Verify License        if(!Getlicense ()) {            return; }        //Template WordString template = "E:\\test\\temp.docx"; //Target WordString DestDoc = "E:\\test\\edit.docx"; //defining the Document interfaceDocument doc =NewDocument (template); //text Fieldstring[] Flds =Newstring[]{"Caseissue", "Policename", "Casename", "Casetime"}; String caseissue= "001"; String Policename= "XX police station"; String Casename= "0727 electric car Theft case"; String Casetime= "2018-07-26 12:20:22"; //valueobject[] Vals =NewObject[]{caseissue,policename, Casename, casetime}; //Calling InterfaceDoc.getmailmerge (). Execute (Flds, Vals);        Doc.save (DestDoc); System.out.println (Complete); }

4, results

Where a picture of the set field is referenced in http://www.xiaoguo123.com/p/aspose_words_java_template/

Aspose.words Java-based template generates plain text content for Word

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.