CN111950247A - Configuration-based Word document generation method - Google Patents
Configuration-based Word document generation method Download PDFInfo
- Publication number
- CN111950247A CN111950247A CN202010650612.0A CN202010650612A CN111950247A CN 111950247 A CN111950247 A CN 111950247A CN 202010650612 A CN202010650612 A CN 202010650612A CN 111950247 A CN111950247 A CN 111950247A
- Authority
- CN
- China
- Prior art keywords
- document
- configuration
- replacement
- file
- word
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 27
- 125000004122 cyclic group Chemical group 0.000 claims abstract description 11
- 230000006835 compression Effects 0.000 claims description 2
- 238000007906 compression Methods 0.000 claims description 2
- 238000010586 diagram Methods 0.000 description 5
- 230000004048 modification Effects 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 230000006837 decompression Effects 0.000 description 2
- 230000001351 cycling effect Effects 0.000 description 1
- 230000014759 maintenance of location Effects 0.000 description 1
- 230000008092 positive effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/10—Text processing
- G06F40/166—Editing, e.g. inserting or deleting
- G06F40/186—Templates
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/10—Text processing
- G06F40/166—Editing, e.g. inserting or deleting
- G06F40/177—Editing, e.g. inserting or deleting of tables; using ruled lines
- G06F40/18—Editing, e.g. inserting or deleting of tables; using ruled lines of spreadsheets
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Health & Medical Sciences (AREA)
- Artificial Intelligence (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Document Processing Apparatus (AREA)
Abstract
The invention provides a configuration-based Word document generation method, which comprises the following steps: establishing a Word template document; a step of positioning a target object, which is to decompress the Word template document and extract an XML file of the Word template document so as to position an XML target object to be operated; establishing a configuration file, wherein the configuration file is used for marking the target object, the replacement type and the replacement content of the target object; generating a Word document, namely generating the configured Word document after carrying out replacement operation on a target object in the document according to the configuration file, wherein the replacement operation further comprises the following steps: cyclic replacement operation, conditional replacement operation. By adopting the Word document generation method of the scheme, the replacement, the cyclic replacement and the conditional replacement of the content and the picture file in the Word document are realized, the structure and the style of the document are ensured not to be falsified, and the format document generation efficiency is improved.
Description
Technical Field
The invention belongs to the technical field of document processing, and particularly relates to a configuration-based Word document generation method.
Background
Word documents are some existing office systems, and after Word2007, we use docx, which is based on a new XML compressed file format, and after decompression, main contents of the Word documents are saved in folders or XML files under the Word.
In government or enterprise systems, documents are often printed out as required by legal checks, and the associated principal is found to sign and seal, sometimes requiring rescanning of the retention.
In the prior art, word documents are often operated through POI, jacob, java2word and other technical means, and the document modification is realized by directly adding explicit parameters in a $ { name } format into the word documents to fill data, but in this way, the whole word template is impure, and in case the explicit parameters are tampered, the function of filling data cannot be used; while such a manner of operation supports less operation for which cycling and condition requirements exist.
Disclosure of Invention
In order to solve the technical problems, the invention provides a configuration-based Word document generation method, which realizes the replacement, the cyclic replacement and the condition replacement of contents and picture files in a Word document, ensures that the structure and the style of the document are not falsified and improves the generation efficiency of format documents.
The invention discloses a configuration-based Word document generation method, which comprises the following steps:
a step S1 of establishing a Word template document, namely establishing a Word template document according to the document with the required format;
a target object positioning step S2, decompressing the Word template document, and extracting an XML file of the Word template document to position an XML target object to be operated;
a step S3 of creating a configuration file, wherein the configuration file is used for marking the target object, the replacement type and the replacement content thereof so as to ensure that the structure and the style of the document are not tampered;
a step S4 of generating a Word document, in which a target object in the document is replaced according to the configuration file, and then the configured Word document is generated, and in order to replace paragraph contents in the Word document according to conditions or replace multiple times for objects that require a loop operation on multiple lines of data in a table in the document, the replacement operation further includes: cyclic replacement operation, conditional replacement operation.
Further, the target object is a target file or a target node, specifically, a node path or a file name of the target object, the target file includes but is not limited to a picture file, the target node includes but is not limited to a text content node and a table node, and the substitute content includes a variable name expression; .
Further, the step of generating the Word document further comprises:
a step of replacing the target file, which is to analyze the configuration file to obtain a variable name expression corresponding to the target file, and obtain a value corresponding to the variable name in the configuration parameter to replace the variable name expression to obtain a configured XML file;
a step of replacing a target node, which is to replace the target node and the corresponding variable name expression of the configuration file to generate a Freemarker template by replacing the target node with the variable name expression, simultaneously obtain the value of the corresponding variable name in the configuration parameters, and obtain a configured XML file after being rendered by the Freemarker;
a Word document generating step, acquiring the configured XML file, generating the configured Word document by the configured XML file in a compression mode,
according to the method, as for the situation of the step of replacing the target node, the Word is templated by generating the Freemarker template, dynamic contents in the document, namely the target node, can be replaced by the variable name expression through the Freemarker template, the generation of the document can be completed by replacing the variable name expression with the configuration parameters, the time consumption of document operation is reduced, and compared with the method of directly adding the variable name expression in the Word, the error rate is reduced.
Further, the loop replacement operation realizes loop replacement by inserting loop tags < # list > </list > to surround the target node.
Further, the conditional replacement operation realizes conditional replacement by inserting a conditional tag < # if > </if > to surround the target node.
Further, the alternative types further include: content replacement, file replacement, conditional replacement, loop replacement, or any combination thereof.
Further, the positioning the target object step positions the target object through an XML file editing software.
Further, the XML file editing software is XMLQuire.
Further, the configuration file is stored through an Excel table.
Further, the data structure of the configuration parameter is a JSON type.
Compared with the prior art, the invention has the advantages and positive effects that:
the Word document generation method can support circulation and conditional statements, is suitable for various application scenes, and effectively improves the generation efficiency of format documents;
the invention combines the fixed template file with the configuration parameters and the collected signature and official seal file to generate the required document, and the required document can be directly printed, thereby saving the labor cost and improving the working efficiency.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive labor.
FIG. 1 is a flow chart of a Word document generating method according to an embodiment of the present invention;
FIG. 2 is a schematic structural diagram of a Word template document after decompression according to an embodiment of the present invention;
fig. 3 is a schematic diagram of a preferred embodiment of a configuration file according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described clearly and completely with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only some embodiments, not all embodiments, of the present invention.
Fig. 1 is a schematic flow diagram of a Word document generating method according to an embodiment of the present invention, and referring to fig. 1, the embodiment of the present invention discloses a Word document generating method based on configuration, including:
a step S1 of establishing a Word template document, namely establishing a Word template document according to the document with the required format;
a target object positioning step S2, decompressing the Word template document, and extracting the XML file of the Word template document to position the target object to position the XML target object to be operated;
a step S3 of creating a configuration file, where the configuration file is used to mark a target object, a replacement type, and replacement content thereof, and store the target object, the target object is a target file or a target node, the target file includes but is not limited to a picture file, the target node includes but is not limited to a text content node and a table node, specifically, the target object is obtained by obtaining a node path or a file name of the target node, the replacement content includes a variable name expression, the replacement type includes one of or any combination of content replacement, file replacement, condition replacement, and cyclic replacement, and in an application process, the replacement type can be selected according to requirements of a format document;
a step S4 of generating a Word document, in which a target object in the document is replaced according to the configuration file, and then a configured Word document is generated, and in order to replace the content in the Word document according to the conditions or replace the object in the document that needs to be cyclically operated for multiple times, the replacing operation further includes: the method comprises the following steps of (1) cyclic replacement operation and conditional replacement operation, wherein the cyclic replacement operation is realized by inserting cyclic tags < # list > </list > to surround target nodes; the conditional replace operation surrounds the target node by inserting a conditional tag < # if > </if >.
Wherein the step S4 of generating Word document further comprises:
a step S41 of replacing the target file, which is to analyze the configuration file to obtain a variable name expression corresponding to the target file, and obtain the value of the corresponding variable name in the configuration parameter to replace the variable name expression to obtain a configured XML file;
step S42, after analyzing the target node of the configuration file and the corresponding variable name expression, generating a Freemarker template by replacing the target node with the variable name expression, simultaneously acquiring the value of the corresponding variable name in the configuration parameter, and obtaining the configured XML file after being rendered by the Freemarker;
and a Word document generating step S43, acquiring the configured XML file, and generating the configured Word document by compressing the configured XML file.
A Word document generating method of the present embodiment is illustrated as an example.
A step S1 of establishing a Word template document, wherein a Word template document is established according to the document with the required format, and the format of the Word template document is docx;
a step S2 of locating a target object, which is known by referring to the schematic structural diagram of the decompressed Word template document shown in fig. 2, in the directory of the Word file of the decompressed docx document, the media folder is used for storing files such as pictures in the document, and document.
Step S3 of creating a configuration file, refer to an embodiment of a schematic diagram of the configuration file shown in fig. 3, where a column of a target object is used to store a path expression, the path expression is an XPath in document. xml or a storage path of a picture file in a Word folder, the replacement type is CONTENT replacement CONTENT, cyclic replacement WRAP _ LOOP, conditional replacement WRAP _ IF, or picture replacement MEDIA, the replacement CONTENT is respectively specified according to the difference of the target object, the replacement CONTENT of the CONTENT replacement or picture replacement type adopts a variable name expression $ { variable name }, such as $ { user.
And a Word document generating step S4, wherein the program analyzes the configuration file and executes the replacement operation corresponding to the target object in the configuration file:
a step S41 of replacing the target file, which is mainly used to replace the picture file, obtain a variable name expression corresponding to the target file, such as $ { user. image } through the program parsing configuration file, and obtain a value corresponding to the variable name in the configuration parameter to replace the variable name expression, so as to obtain a configured XML file;
replacing the target node step S42, which is mainly used for replacing the content in the document xml, first analyzing the target node of the configuration file and the corresponding variable name expression, and then generating a freemaker template by replacing the target node with the variable name expression: meanwhile, obtaining the value of the corresponding variable name in the configuration parameter, and generating a configured XML file by combining corresponding data after being rendered by a Freemarker;
and a Word document generating step S43, acquiring the configured XML file, and generating the configured Word document by compressing the configured XML file.
In step S42, for the CONTENT replacement control type, the CONTENT in XPATH is replaced by $ { user. username }, $ { user. image } and updated to the node corresponding to the XML file CONTENT, such as "/w: document/w: body/w: tbl/w: tr [2]/w: tc [2 ]", for conditional CONTENT conditional replacement, the node where the CONTENT is located is surrounded by < # if > </if >, such as "/w: document/w: body/w: tbl/w: tr [2 ]", for list loop replacement is needed, the node needing replacement is surrounded by < # if > </st >, such as "</t 2 ]", for example/w: document/w: body/w: tbl/w: tb [2], and note that when inserting the text label, the text label can be inserted first! - - - >, as by the following statement: < | A! The cyclic replacement tag is annotated, and the annotation tag is only deleted before the freemarker is rendered, so that the XML file is protected through the annotation tag, and the XML grammar structure is prevented from being damaged in the editing process.
The data structure of the configuration parameters in this embodiment is a JSON type, for example, as follows:
the above description is only a preferred embodiment of the present invention, and not intended to limit the present invention in other forms, and any person skilled in the art may apply the above modifications or changes to the equivalent embodiments with equivalent changes, without departing from the technical spirit of the present invention, and any simple modification, equivalent change and change made to the above embodiments according to the technical spirit of the present invention still belong to the protection scope of the technical spirit of the present invention.
Claims (10)
1. A configuration-based Word document generation method is characterized by comprising the following steps:
establishing a Word template document, namely establishing a Word template document according to the document with the required format;
a step of positioning a target object, which is to decompress the Word template document and extract an XML file of the Word template document so as to position an XML target object to be operated;
establishing a configuration file, wherein the configuration file is used for marking the target object, the replacement type and the replacement content of the target object;
generating a Word document, namely generating the configured Word document after carrying out replacement operation on a target object in the document according to the configuration file, wherein the replacement operation further comprises the following steps: cyclic replacement operation, conditional replacement operation.
2. A configuration-based Word document generating method as recited in claim 1, wherein the target object is a target file or a target node, and the substitute content includes a variable name expression.
3. The configuration-based Word document generating method of claim 2 wherein the generating a Word document step further comprises:
a step of replacing the target file, which is to analyze the configuration file to obtain a variable name expression corresponding to the target file, and obtain a value corresponding to the variable name in the configuration parameter to replace the variable name expression to obtain a configured XML file;
a step of replacing a target node, which is to replace the target node and the corresponding variable name expression of the configuration file to generate a Freemarker template by replacing the target node with the variable name expression, simultaneously obtain the value of the corresponding variable name in the configuration parameters, and obtain a configured XML file after being rendered by the Freemarker;
and a Word document generation step, namely acquiring the configured XML file, and generating the configured Word document from the configured XML file in a compression mode.
4. A configuration-based Word document generation method according to claim 1 or 3, characterized in that the loop replacement operation implements loop replacement by inserting loop tags < # list > </list > around the target node.
5. A configuration-based Word document generation method as claimed in claim 4, wherein the conditional replacement operation implements conditional replacement by inserting a conditional tag < # if > </if > around the target node.
6. The configuration-based Word document generating method of claim 5, wherein the alternate type further comprises: content replacement, file replacement, conditional replacement, loop replacement, or any combination thereof.
7. A method of generating a Word document based on configuration as in claim 6 wherein the step of locating the target object locates the target object by an XML file editing software.
8. A configuration-based Word document generating method as recited in claim 7, wherein the XML file editing software is XMLQuire.
9. A method of generating a Word document based on configuration as claimed in claim 1 wherein the configuration file is stored by an Excel table.
10. A configuration-based Word document generation method in accordance with claim 3, wherein the data structure of the configuration parameters is of JSON type.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010650612.0A CN111950247A (en) | 2020-07-08 | 2020-07-08 | Configuration-based Word document generation method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010650612.0A CN111950247A (en) | 2020-07-08 | 2020-07-08 | Configuration-based Word document generation method |
Publications (1)
Publication Number | Publication Date |
---|---|
CN111950247A true CN111950247A (en) | 2020-11-17 |
Family
ID=73341422
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010650612.0A Pending CN111950247A (en) | 2020-07-08 | 2020-07-08 | Configuration-based Word document generation method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111950247A (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112765948A (en) * | 2020-12-31 | 2021-05-07 | 山西三友和智慧信息技术股份有限公司 | Document generation editing method |
CN113011151A (en) * | 2021-04-20 | 2021-06-22 | 平安科技(深圳)有限公司 | Method, device and equipment for generating requirement document template and storage medium |
CN113378535A (en) * | 2021-06-23 | 2021-09-10 | 浪潮软件科技有限公司 | Method and system for generating docx format document based on freemarker |
CN115062252A (en) * | 2022-06-15 | 2022-09-16 | 江苏未至科技股份有限公司 | Method for solving format conflict of webpage generation file when WPS and Word are opened |
WO2023115833A1 (en) * | 2021-12-24 | 2023-06-29 | 永中软件股份有限公司 | Streaming document generation method, computing device, and computer readable medium |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101989256A (en) * | 2009-07-31 | 2011-03-23 | 北京大学 | Typesetting method of document file and device |
CN103559322A (en) * | 2013-11-22 | 2014-02-05 | 方正国际软件有限公司 | Document format conversion method |
WO2016015564A1 (en) * | 2014-07-31 | 2016-02-04 | 广州金山网络科技有限公司 | Method and apparatus for displaying document |
CN106874244A (en) * | 2017-01-03 | 2017-06-20 | 宁波大红鹰学院 | A kind of construction method of the document Auto-generation Model based on work sequence |
CN108052488A (en) * | 2017-12-06 | 2018-05-18 | 广东技术师范学院天河学院 | A kind of paper automatic generation method based on template |
CN111159995A (en) * | 2020-01-16 | 2020-05-15 | 江西金格科技股份有限公司 | Method for generating word document in template mode |
-
2020
- 2020-07-08 CN CN202010650612.0A patent/CN111950247A/en active Pending
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101989256A (en) * | 2009-07-31 | 2011-03-23 | 北京大学 | Typesetting method of document file and device |
CN103559322A (en) * | 2013-11-22 | 2014-02-05 | 方正国际软件有限公司 | Document format conversion method |
WO2016015564A1 (en) * | 2014-07-31 | 2016-02-04 | 广州金山网络科技有限公司 | Method and apparatus for displaying document |
CN106874244A (en) * | 2017-01-03 | 2017-06-20 | 宁波大红鹰学院 | A kind of construction method of the document Auto-generation Model based on work sequence |
CN108052488A (en) * | 2017-12-06 | 2018-05-18 | 广东技术师范学院天河学院 | A kind of paper automatic generation method based on template |
CN111159995A (en) * | 2020-01-16 | 2020-05-15 | 江西金格科技股份有限公司 | Method for generating word document in template mode |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112765948A (en) * | 2020-12-31 | 2021-05-07 | 山西三友和智慧信息技术股份有限公司 | Document generation editing method |
CN112765948B (en) * | 2020-12-31 | 2024-01-19 | 山西三友和智慧信息技术股份有限公司 | Document generation editing method |
CN113011151A (en) * | 2021-04-20 | 2021-06-22 | 平安科技(深圳)有限公司 | Method, device and equipment for generating requirement document template and storage medium |
CN113011151B (en) * | 2021-04-20 | 2022-03-18 | 平安科技(深圳)有限公司 | Method, device and equipment for generating requirement document template and storage medium |
CN113378535A (en) * | 2021-06-23 | 2021-09-10 | 浪潮软件科技有限公司 | Method and system for generating docx format document based on freemarker |
WO2023115833A1 (en) * | 2021-12-24 | 2023-06-29 | 永中软件股份有限公司 | Streaming document generation method, computing device, and computer readable medium |
CN115062252A (en) * | 2022-06-15 | 2022-09-16 | 江苏未至科技股份有限公司 | Method for solving format conflict of webpage generation file when WPS and Word are opened |
CN115062252B (en) * | 2022-06-15 | 2023-09-19 | 江苏未至科技股份有限公司 | Method for solving format conflict of webpage generation file when WPS and Word are opened |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111950247A (en) | Configuration-based Word document generation method | |
US7975215B2 (en) | Sharing editable ink annotated images with annotation-unaware applications | |
CN101271463B (en) | Structure processing method and system of layout file | |
US20110087959A1 (en) | Method and device for processing the structure of a layout file | |
JP2015529874A (en) | System and method for viewing medical images | |
CN113609820A (en) | Method, device and equipment for generating word file based on extensible markup language file | |
CN106547782A (en) | The acquisition methods and device of log information | |
WO2020015220A1 (en) | Method and apparatus for downloading data based on pdf document, and storage medium and terminal | |
JP2004102926A (en) | Identifier generating method, identity determining method, identifier sending method, identifier generating device, identity determining device, and identifier sending device | |
US8930808B2 (en) | Processing rich text data for storing as legacy data records in a data storage system | |
CN104820962A (en) | Method for generating and printing watermarks capable of replacing manual signatures | |
US7594169B2 (en) | Compressing, and extracting a value from, a page descriptor format file | |
CN111679825A (en) | Cascading style sheet generation method and device, computer equipment and storage medium | |
CN111241096A (en) | Text extraction method, system, terminal and storage medium for EXCEL document | |
CN112069549B (en) | Method and system for downloading picture when Bootstrap-table plug-in exports table | |
CN101894098B (en) | Embedded font data processing method and device | |
CN107391127A (en) | Software version information store method and system | |
CN109948123B (en) | Image merging method and device | |
CN109509467B (en) | Code generation method and device | |
CN102262784B (en) | Method for coding and decoding word library based on image compression | |
CN112818642B (en) | Method and device for converting PDF (Portable document Format) file into form file, computer equipment and storage medium | |
KR101165201B1 (en) | Conversion server for a contents providing system | |
JPWO2005101210A1 (en) | Data analysis apparatus and data analysis program | |
US20120072827A1 (en) | Information processing apparatus, page description method, and storage medium | |
CN110060310B (en) | File compression method, device and equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |