Word Template Engine User Guide

1 Introduction

    A Docx template is a tagged Word document, and the template engine replaces these tags with data to generate a new Word document. 

   This is a document and a template that will be used in the examples that follow.

        Word document address: http://www.xdocin.com/DocxEngine.docx

2. Features

  • Visual editing using Word, easy to operate
  • Markup syntax is easy to learn
  • 100% compatible with document styles
  • Rich data formats
  • Cloud-based service, no installation and maintenance required

3. Markup syntax

   ${name}

   The front and rear marks must be half-width, and the incoming data will be automatically recognized according to the following rules:

4. Identification Rules 

  • Text starting with "http:", "https:", "ftp:", "data:" represents a network resource and is automatically recognized as an image or document
  • Data starting with "text:" is recognized as text after removing "text:"
  • Values ​​containing carriage returns are recognized as multi-line text
  • Alternative text for tables, text boxes - title tags recognized as CSV list data
  • Others are recognized as single-line text

5. Text markup

Text tags are entered directly in the document.

Example

Single-line text:  ${single-line text}

Multi-line text:  ${multi-line text}

Image:  ${image}

Image in textbox:

  

   When there is only one picture in the text box, the picture will be resized according to the size of the text box

HTML: ${HTML}

URL address:  ${URL address}

Web Documentation:  ${document}

6.【Optional text】-【Title】mark

picture

set up

Insert a sample image, open [Format Image], and enter a tag in [Optional Text] - [Title], as shown below:

Example

sheet

set up

Insert a table, open the [Table Properties] dialog box, and enter a tag in [Alternative Text] - [Title], as shown in the following figure:

Define the header by setting [Repeat Header Row], the header can be multiple lines, as shown below:

The first row under the header is the data row, and the data row will be displayed repeatedly according to the number of incoming data.

If the header is not set, the first row is the data row.

Enter the tag in the data line, the name of the tag is the field name of the list, or it can refer to the global tag.

Below the data row is the footer, which is optional.

If no data is passed in, the form will not be displayed.

Example

name

information

logo

Market value (billion US dollars)

${name}

 

${market cap}

company information

text box

set up

Insert a text box, set the [Position] of the text box to [Embed in text line], as shown below:

Open [Format Shape], and enter a tag in [Optional Text] - [Title], as shown below:

Enter the tag in the text box, the name of the tag is the field name of the list, or it can refer to the global tag.

The data row will be displayed repeatedly according to the number of incoming data. If no data is passed in, the text box is not displayed.

Example

7. Invoke

Java

library

   http://www.xdocin.com/XDocService.jar

Example

 

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import com.hg.xdoc.XDocService;

public class DocxEngineDemo {
	public static void main(String[] args) {
		Map<String, Object> params = new HashMap<String, Object>();
		try {
			params.put("Single line text", "Hello!");
			params.put("Multi-line text", "one line\ntwo lines\nthree lines");
			params.put("图片", "http://www.xdocin.com/xdoc.png");
			params.put("HTML", "<html><li>张小三</li><li>李小四</li><li>王小五</li></html>");
			params.put("URL地址", "text:http://www.baidu.com");
			params.put("文档", "http://www.xdocin.com/xdoc?_func=hi&_rformat=html");
			params.put("Company", "Name, Logo, Market Value\n"
					+ "Tencent,http://www.logodashi.com/OldPic/635467462172730000.gif,3000\n"
					+ "Alibaba,http://www.logodashi.com/OldPic/635521864517328000.jpg,2900\n"
					+ "Baidu,http://www.logodashi.com/OldPic/635467448562000000.gif,600");
			new XDocService().run("http://www.xdocin.com/DocxEngine.docx", params,
					new File("d:/DocxEngineResult.docx"));
		} catch (Exception e) {
			e.printStackTrace ();
		}
	}
}

Note: Templates are local files or URLs.

Web

Example

 

<script type= "text/javascript"  src= "http://www.xdocin.com/xdoc.js" ></script>
<script type= "text/javascript" >
XDoc.run( "http://www.xdocin.com/DocxEngine.docx" ,  "docx" ,
{ "Single-line text" : "Hello!" , "Multi-line text" : "One line\nTwo lines\nThree lines" , "Picture" : "http://www.xdocin.com/xdoc.png" ,
"HTML" : "<html><li>Zhang Xiaosan</li><li>Li Xiaosi</li><li>Wang Xiaowu</li></html>" ,
"URL地址" :  "text:http://www.baidu.com" , "文档" :  "http://www.xdocin.com/xdoc?_func=hi&_rformat=html" ,
"company" : "name, logo, market capitalization\n"
  + "Tencent,http://www.logodashi.com/OldPic/635467462172730000.gif,3000\n"
  + "Alibaba,http://www.logodashi.com/OldPic/635521864517328000.jpg,2900\n"
  + "Baidu,http://www.logodashi.com/OldPic/635467448562000000.gif,600"
},  "_blank" );
</script>
 

 

Note: The template address needs to be accessible from the external network, or it is a DataURI.

http

call address

http://www.xdocin.com/xdoc?_func=run&_format=docx&_xdoc=template&tagname=tagvalue

   Templates, tag names, and tag values ​​must be encoded in UTF-8. If there are many parameters, please call them in POST mode.

Note: The template address needs to be accessible from the external network, or it is a DataURI.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326390079&siteId=291194637