After work experience needed to deal with the situation based on different data template word, a lot of online search and found the library called docxtemplater, very portable, very meet this demand.
The record came about the use of docxtemplater.
docxtemplater official website: https://docxtemplater.readthedocs.io/en/latest/index.html
1. Install
And other libraries, there are a variety of installation, used here is npm install
npm install docxtemplater pizzip --save-dev
pizzip is a synchronous compression library file, is a branch of JsZip
2. Copy the official website can be directly provided by the production code word
3. Write the placeholder in the word
Code written into the corresponding data
Run the code, the output of the new word
4. Label Type
(1) Conditions
# Condition tag to the beginning / end, the following
When hasKitty is true, only to render its contents
(2) cycle
The same cycle to # beginning / end, the following
(3)sections
Condition tag, label circulation, in fact, are based on the grammar section, beginning with #, / end, to constitute a zone, so as to obtain the corresponding data.