A method of automatically filling in tables based on freemarker
Patent Information
- Application Number
- CN202111443569.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2041-11-30
AI Technical Summary
但是表格数据的拓展,需要在ftl格式的模版文件中插入freemarker指定的语法,而这个语法的插入目前都是手动的进行修改,容错率和效率都低
[0023] The present invention provides a method of automatically filling a form based on freemarker. Have the following beneficial effects:
Smart Images

Figure CN114118015B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of contract generation, in particular to a method for automatically filling a form based on Freemarker. Background Art
[0002] FreeMarker is a template engine: a general tool for generating output text (HTML pages, emails, configuration files, source code, etc.) based on templates and data to be changed. It is not for end users, but a Java class library, a component that programmers can embed into the products they develop, and the templates are written in FreeMarker Template Language (FTL). It is a simple, dedicated language, not a mature programming language like PHP. That means preparing data for display in a real programming language, such as database queries and business operations, and then the template displays the prepared data. In the template, you can focus on how to display the data, and outside the template you can focus on what data to display.
[0003] The Freemarker framework is generally used for document generation, and for contract documents, it is often necessary to fill in tables with data expansion. However, the expansion of table data requires the insertion of the Freemarker-specified syntax in the ftl-format template file, and the insertion of this syntax is currently manually modified, with low fault tolerance and efficiency. Summary of the invention
[0004] 1. Technical issues to be resolved
[0005] In view of the deficiencies of the prior art, the present invention provides a method for automatically filling in a table based on Freemarker, which solves the problems raised by the above background technology.
[0006] (II) Technical solution
[0007] To achieve the above objectives, the present invention is implemented by the following technical scheme: a method for automatically filling in a table based on freemarker, the method for automatically filling in a table based on freemarker comprising the following steps:
[0008] Step 1: Using the freemarker framework to define table-type variables is quite special. You need to insert special syntax into the specified position in the tag. The freemarker framework normally generates the final document.
[0009] Step 2: First define a mapping relationship between Chinese description and table variables, such as ${table variable-asset number} and ${asset.assetNo! '}. In the initial word document stage, the business personnel inserted the Chinese description;
[0010] Step 3: Convert the word document into an XML file;
[0011] Step 4: Traverse the tags inside to see if there is one <w:tbl>The tag exists. If so, then traverse <w:tbl>Sub-tags, mainly look at the sub-tags <w:tr>,have a look <w:tr>Sub-tags of <w:t>Whether the text contained in contains the Chinese description corresponding to the table variable;
[0012] Step 5: The variables of the table need to be extracted again, because in the freemarker framework, if you want to dynamically expand the table, you need to add a variable in the table tag. <w:tr>Before the , insert the special syntax for table expansion: <#list list variable name asvar>, and <w:t>The corresponding end tag< / w:t> Insert from behind< / #list> ;
[0013] Step 6. Finally, use the freemarker framework to combine with the actual data to generate the final contract (in electronic computers, tags refer to information symbols that can be understood by computers. Through this tag, computers can process various information such as articles. By converting the world document into an XML file and processing the XML file through freemarker, the final contract can be generated quickly and office efficiency can be improved).
[0014] Preferably, the word document is <w:ttbl>The tag represents a table, and <w:ttbl>Inside, through <w:tr>The label represents a row in the table, and each row is represented by <w:tc>A label represents a column in a row; text in a table is represented in <w:t>Defined in the tag (XML is simple and easy to read / write data in any application, which makes XML quickly become the only common language for data exchange. Although different application software also supports other data exchange formats, by converting world documents into XML files, it can ensure that the writing process is more convenient, while improving the efficiency of the final generated contract and the accuracy of the final generated contract).
[0015] Preferably, the further step method of step four includes: if there is no Chinese description corresponding to the table variable, there is no need to replace the variable. Then the final result generated, combined with the freemarker <#list> tag added later, has the same text in the column corresponding to each row. If there is, the freemarker format syntax corresponding to the Chinese description needs to be replaced.
[0016] Preferably, the further method of step 4 includes: if yes, then the freemarker format syntax corresponding to the Chinese description needs to be replaced.
[0017] Preferably, the further step method of step five includes: the meaning of this syntax is to indicate that the list variable name in the <#list list variable name asvar> tag needs to be traversed, and each traversal will dynamically expand the label in <#list>, thereby dynamically expanding the label of each row to realize the demand for dynamic expansion of the table.
[0018] Preferably, the further steps of step 4 include: in freemarket, we obtain the elements in the passed-in list by the list name, the internal element name, such as asset.amount.
[0019] Preferably, the further step method of step three includes: backing up the word document before converting the word document into an xml file, and backing up the xml file after converting the word document into an xml file (by backing up the word document after converting it into an xml file, it is possible to prevent the word document from being damaged when an error occurs during the conversion process, protect the original file from being damaged when an error occurs, increase office efficiency, and improve the feasibility of the entire method. At the same time, when an error occurs in the conversion and the file is damaged, it can be corrected in time, making the entire workflow smoother).
[0020] Preferably, the further step method of step six includes: backing up the actual data of the final generated contract, and comparing the data on the final generated contract (by backing up the actual data, the final generated contract can be prevented from being damaged, and the contract can be quickly regenerated, thereby improving learning efficiency. After the contract is generated, the final generated contract can be backed up to prevent the final generated contract from being damaged, thereby improving office efficiency. At the same time, by backing up during the conversion of each stage, it can be ensured that when an error occurs during the file conversion, the original file is retained, thereby improving office efficiency).
[0021] Preferably, the further steps of step one include: going through the following stages: initial world document → XML file → ftl file → final generated contract, and the processing of table variables needs to be processed in the xml file stage.
[0022] (III) Beneficial effects
[0023] The present invention provides a method for automatically filling in a table based on freemarker. It has the following beneficial effects:
[0024] (1) This method of automatically filling in a table based on Freemarker converts the world document into an XML file and processes the table variables, so that the syntax can be automatically inserted, thereby improving the efficiency of syntax insertion.
[0025] (2) This method of automatically filling in tables based on Freemarker converts the world document into an XML file and then processes the table variables. This reduces the error rate while ensuring that the learning cost is reduced, thereby improving the quality of the final generated contract.
[0026] (3) This method of automatically filling in tables based on Freemarker can ensure the retention of the original file when an error occurs during file conversion by backing up the file during each stage of conversion, thereby improving office efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a schematic diagram of the overall process structure of the present invention;
[0028] Figure 2 For the present invention <w:ttbl>A structural schematic diagram of;
[0029] Figure 3 It is a structural schematic diagram before and after freemarker conversion of the present invention. DETAILED DESCRIPTION
[0030] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] See also Figure 1-Figure 3 The present invention provides a technical solution: the method for automatically filling in a table based on freemarker comprises the following steps:
[0032] Step 1: Using the freemarker framework to define table-type variables is quite special. You need to insert special syntax into the specified position in the tag. The freemarker framework normally generates the final document.
[0033] Step 2: First define a mapping relationship between Chinese description and table variables, such as ${table variable-asset number} and ${asset.assetNo! '}. In the initial word document stage, the business personnel inserted the Chinese description;
[0034] Step 3: Convert the word document into an XML file;
[0035] Step 4: Traverse the tags inside to see if there is one <w:tbl>The tag exists. If so, then traverse <w:tbl>Sub-tags, mainly look at the sub-tags <w:tr>,have a look <w:tr>Sub-tags of <w:t>Whether the text contained in contains the Chinese description corresponding to the table variable;
[0036] Step 5: The variables of the table need to be extracted again, because in the freemarker framework, if you want to dynamically expand the table, you need to add a variable in the table tag. <w:tr>Before the , insert the special syntax for table expansion: <#list list variable name asvar>, and <w:t> The corresponding end tag< / w:t> Insert from behind< / #list> ;
[0037] Step 6. Finally, use the freemarker framework and actual data to generate the final contract.
[0038] In electronic computers, tags refer to information symbols that can be understood by computers. Through this tag, computers can process various information such as articles. By converting the world document into an XML file and processing the XML file through freemarker, the final contract can be generated quickly and office efficiency can be improved.
[0039] Furthermore, the word document is created through <w:ttbl>Tag to represent a table, and <w:ttbl>Inside, through <w:tr>The label represents a row in the table, and each row is represented by <w:tc>A label represents a column in a row; text in a table is represented in <w:t>Defined in the tag, XML is simple and easy to read / write data in any application, which makes XML quickly become the only common language for data exchange. Although different application software also supports other data exchange formats, by converting world documents into XML files, it can ensure that the writing process is more convenient, while improving the efficiency of the final generated contract and the accuracy of the final generated contract.
[0040] Furthermore, the further steps of step 4 include: if there is no Chinese description corresponding to the table variable, there is no need to replace the variable, then the final result, combined with the freemarker <#list> tag added later, is the same text in each row corresponding to the column. If there is, then the freemarker format syntax corresponding to the Chinese description needs to be replaced. If there is, then the freemarker format syntax corresponding to the Chinese description needs to be replaced. If the content in the table is in freemarker, we generally encapsulate it into an object, assemble it into a list and pass it to the freemarker framework. For example, there is a class as follows:
[0041] class Asset{private String amount;}
[0042] Then we need to pass a list, List <asset>asset. The simple code is as follows:
[0043] List <asset>asset = new ArrayList<>();
[0044] asset.add(new Asset());
[0045] asset.add(new Asset());
[0046] The further steps of step 4 include: In freemarket, we get the elements in the passed list by the list name and the internal element name, such as asset.amount. Therefore, in freemarker, after replacing the freemarker format syntax corresponding to the Chinese description, it becomes as follows:
[0047]
[0048]
[0049] Furthermore, the further steps of step three include: backing up the word document before converting it to an xml file, and backing up the xml file after converting it to an xml file. By backing up the word document after converting it to an xml file, it is possible to prevent the word document from being damaged when an error occurs during the conversion process, protect the original file from being damaged when an error occurs, increase office efficiency, and improve the feasibility of the entire method. At the same time, when an error occurs in the conversion and the file is damaged, it can be corrected in time, making the entire workflow smoother.
[0050] Furthermore, the further step method of step six includes: backing up the actual data of the final generated contract, and comparing the data on the final generated contract. By backing up the actual data, the final generated contract can be prevented from being damaged, and the contract can be quickly regenerated, thereby improving learning efficiency. After the contract is generated, the final generated contract is backed up to prevent the final generated contract from being damaged, thereby improving office efficiency. At the same time, by backing up during the conversion of each stage, it can be ensured that when an error occurs during the file conversion, the original file is retained, thereby improving office efficiency.
[0051] Furthermore, the further steps of step one include: going through the following stages: initial world document → XML file → ftl file → final generated contract, and the processing of table variables needs to be processed in the xml file stage.
[0052] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.< / asset> < / asset> < / w:t> < / w:tc> < / w:tr> < / w:ttbl> < / w:ttbl> < / w:tr> < / w:t> < / w:tr> < / w:tr> < / w:tbl> < / w:tbl> < / w:ttbl> < / w:t> < / w:tc> < / w:tr> < / w:ttbl> < / w:ttbl> < / w:tr> < / w:t> < / w:tr> < / w:tr> < / w:tbl> < / w:tbl>
Claims
1. A method for automatically filling in a table based on freemarker, characterized in that: The freemarker-based method for automatically filling in tables includes the following steps: Step 1: Using the freemarker framework to define table-type variables is quite special. You need to insert special syntax into the specified position in the tag. The freemarker framework normally generates the final document. Step 2: First define a mapping relationship between Chinese description and table variable, ${table variable-asset number} and ${asset.assetNo! '}. In the initial word document stage, the business personnel inserted the Chinese description; Step 3: Convert the word document into an XML file; Step 4: Traverse the tags inside to see if there is any <w:tbl>The tag exists, if so, then traverse <w:tbl>Sub-tags, see Sub-tags <w:tr>, check <w:tr>Sub-tags of <w:t> Whether the text contained in contains the Chinese description corresponding to the table variable;< / w:t> < / w:tr> < / w:tr> < / w:tbl> < / w:tbl> Step 5: Extract the variables of the table again, because in the freemarker framework, if you want to dynamically expand the table, you need to add the table tag <w:tr>Before the , insert the special syntax for table expansion: <#list list variable name asvar>, and <w:t> The corresponding end tag< / w:t> Insert from behind< / #list> ;< / w:tr> Step 6. Finally, use the freemarker framework to combine with the actual data to generate the final contract; The further steps of step 4 include: if there is no Chinese description corresponding to the table variable, there is no need to replace the variable. Then the final result, combined with the freemarker <#list> tag added later, has the same text in the columns corresponding to each row. If there is, the freemarker format syntax corresponding to the Chinese description needs to be replaced.
2. According to claim 1, a method for automatically filling in a table based on freemarker is characterized in that: The word document is obtained through <w:ttbl>The tag represents a table, and <w:ttbl>Inside, through <w:tr>The label represents a row in the table, and each row is represented by <w:tc>A label represents a column in a row; text in a table is represented in <w:t> Defined in the tag.< / w:t> < / w:tc> < / w:tr> < / w:ttbl> < / w:ttbl> 3. The method for automatically filling in a table based on freemarker according to claim 1, characterized in that: The further steps of step five include: the meaning of this syntax is to indicate that the list variable name in the <#list list variable name asvar> tag needs to be traversed, and each traversal will dynamically expand the label in <#list>, thereby dynamically expanding the label of each row to meet the demand for dynamic expansion of the table.
4. The method for automatically filling in a table based on freemarker according to claim 1, characterized in that: The further steps of step 4 include: in freemarket, we obtain the elements in the passed list through the list name, the internal element name, and asset.amount.
5. The method for automatically filling in a table based on freemarker according to claim 1, characterized in that: The further steps of step three include: before converting the word document into an xml file, backing up the word document; after converting the word document into an xml file, backing up the xml file.
6. The method for automatically filling in a table based on freemarker according to claim 1, characterized in that: The further steps of step six include: backing up the actual data of the final generated contract and comparing the data on the final generated contract.
7. The method for automatically filling in a table based on freemarker according to claim 1, characterized in that: The further steps of step one include: going through the following stages: initial world document → XML file → ftl file → final generated contract, and the processing of table variables needs to be processed in the xml file stage.
Citation Information
Patent Citations
Template-based document generation method and device, storage medium and apparatus
CN109657215A
Word document generation method based on configuration
CN111950247A