Document generation method, device, equipment and medium based on template engine
By obtaining the initial Word document and tag set in Java, inserting tags and configuring the data model, combined with the POI-TL template engine, the problem of low efficiency in generating Word documents by the FreeMarker template engine is solved, and an efficient process of directly generating new documents is realized.
Patent Information
- Application Number
- CN202111543039.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-16
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-12-16
AI Technical Summary
When using the FreeMarker template engine to generate Word documents in Java, the Word document containing tags needs to be manually converted into an XML structure, resulting in low generation efficiency.
By obtaining the initial Word document and tag set, insert tags into the document according to the tag insertion instructions, configure the tags as data models, and use the POI-TL template engine to load the document to directly generate a new document, avoiding the xml structure conversion process.
It improves the efficiency of generating Word documents in Java, simplifies the operation process, reduces the occurrence of errors, and directly uses existing Word documents as templates to generate new documents.
Smart Images

Figure CN114239529B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of document management, and in particular to a document generation method, device, computer equipment and storage medium based on a template engine. Background Art
[0002] Currently, the FreeMarker template engine is mainly used to generate Word documents in Java. Since FreeMarker itself does not support direct modification of Word documents, it is necessary to manually convert Word documents containing tags into template files with XML structure, and correct the wrong tags in the conversion process before generating a new Word document, which leads to low efficiency in generating Word documents in Java. Summary of the invention
[0003] The embodiments of the present invention provide a document generation method, apparatus, computer equipment and storage medium based on a template engine, aiming to solve the problem in the prior art that when a Word document is generated in Java using a FreeMarker template engine, a Word document containing tags needs to be manually converted into a template file with an XML structure, resulting in low efficiency in generating Word documents in Java.
[0004] In a first aspect, an embodiment of the present invention provides a document generation method based on a template engine, which includes:
[0005] Acquire an initial Word document and a tag set, and insert each tag in the tag set into a corresponding position in the initial Word document according to the received tag insertion instruction to obtain an adjusted Word document;
[0006] configuring the tags in the adjusted Word document into a data model according to a preset key-value pair mapping relationship to obtain a configured Word document; and
[0007] A preset template engine is obtained, and the configured Word document is loaded through the template engine to obtain an updated Word document.
[0008] In a second aspect, an embodiment of the present invention provides a document generation device based on a template engine, comprising:
[0009] A tag insertion unit, used to obtain an initial Word document and a tag set, and insert each tag in the tag set into a corresponding position in the initial Word document according to the received tag insertion instruction to obtain an adjusted Word document;
[0010] A data model configuration unit, configured to configure the tags in the adjusted Word document into a data model according to a preset key-value pair mapping relationship to obtain a configured Word document; and
[0011] The template engine loading unit is used to obtain a preset template engine, load the configured Word document through the template engine, and obtain an updated Word document.
[0012] In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the document generation method based on the template engine described in the first aspect is implemented.
[0013] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the document generation method based on the template engine described in the first aspect above.
[0014] The embodiment of the present invention provides a document generation method, device, computer equipment and storage medium based on a template engine, firstly obtaining an initial Word document and a tag set, inserting each tag in the tag set into a corresponding position in the initial Word document according to a received tag insertion instruction, and obtaining an adjusted Word document; then configuring the tags in the adjusted Word document into a data model according to a preset key-value pair mapping relationship, and obtaining a configured Word document; finally obtaining a preset template engine, loading the configured Word document through the template engine, and obtaining an updated Word document. This method realizes the direct use of an existing Word document as a template to generate a new document, and no longer needs to convert the Word document into an XML structure, thus avoiding errors that may be caused by the conversion process, and improving the efficiency of generating Word documents in Java. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.
[0016] Figure 1 A schematic diagram of an application scenario of a document generation method based on a template engine provided in an embodiment of the present invention;
[0017] Figure 2 A schematic diagram of a process flow of a document generation method based on a template engine provided in an embodiment of the present invention;
[0018] Figure 3A schematic block diagram of a document generation device based on a template engine provided by an embodiment of the present invention;
[0019] Figure 4 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0020] 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 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.
[0021] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0022] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0023] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0024] See also Figure 1 and Figure 2 , Figure 1 A schematic diagram of an application scenario of a document generation method based on a template engine provided in an embodiment of the present invention; Figure 2 A schematic flow chart of a document generation method based on a template engine provided in an embodiment of the present invention. The document generation method based on a template engine is applied in a user terminal, and the method is executed by application software installed in the user terminal.
[0025] like Figure 2 As shown, the method includes steps S101 to S103.
[0026] S101, obtaining an initial Word document and a tag set, and inserting each tag in the tag set into a corresponding position in the initial Word document according to a received tag insertion instruction to obtain an adjusted Word document.
[0027] In this embodiment, the technical solution is described with the user end as the execution subject. Each tag in the tag set includes a start identifier and an end identifier. When the user operates the user end to select an initial Word document and sets a tag set for the initial Word document, each tag in the tag set can be inserted into the corresponding position in the initial Word document, thereby realizing the preliminary editing of the initial Word document.
[0028] For example, a user can preliminarily write an initial Word document on the user side and insert a tag set. Tags in the tag set start with "{{" and end with "}}" (for example, "{{name}}" is a tag), and tags can appear in any position, including headers, footers, inside tables, and text boxes. Of course, for the above boundaries of the initial Word document, the style of the document will be completely retained, and the style of the tag will also be applied to the replaced text, where both the initial Word document and the adjusted Word document are docx format files. After completing the insertion of tags into the initial Word document, the first total number of tags in the adjusted Word document and the second total number of tags in the tag set can be counted respectively. If it is determined that the first total number and the second total number are equal, it means that all tags in the tag set are inserted into the initial Word document and the tag insertion is successfully completed. If it is determined that the first total number is less than the second total number, it means that there are tags in the tag set that have not been inserted into the initial Word document. At this time, a pop-up window can be issued to prompt the user whether to confirm the completion of the tag insertion. Only when the user selects to confirm the completion of the tag insertion can only some tags in the tag set be inserted into the initial Word document.
[0029] In one embodiment, step S101 includes:
[0030] If it is determined that the tag is a header attribute tag, inserting the tag into the header of the initial Word document to obtain an adjusted Word document;
[0031] If it is determined that the tag is a footer attribute tag, inserting the tag into the footer of the initial Word document to obtain an adjusted Word document;
[0032] If it is determined that the tag is a table attribute tag, inserting the tag into the table in the initial Word document to obtain an adjusted Word document;
[0033] If it is determined that the tag is a text box attribute tag, the tag is inserted into the text box in the initial Word document to obtain an adjusted Word document.
[0034] In this embodiment, labels in the format of {{XXX}} can be inserted into the header, footer, inside the table, text box, etc. in the initial Word document, and each additional label in the initial Word document will update the initial Word document until the label editing is completed to obtain the final updated and saved adjusted Word document in the editing stage. In this way, based on the "what you see is what you get" feature of the template engine used later, the style of the document will be completely retained, and the style of the label will also be applied to the replaced text. Moreover, the label insertion process is simple and does not require complicated operations, which reduces the learning cost of operators and improves development efficiency.
[0035] S102: configuring the tags in the adjusted Word document into a data model according to a preset key-value pair mapping relationship to obtain a configured Word document.
[0036] In this embodiment, after the adjusted Word document is obtained, all tags therein need to be configured into a data model based on a preset key-value pair mapping relationship, that is, each tag is converted into a corresponding specific value, thereby obtaining a configured Word document.
[0037] In one embodiment, step S102 includes:
[0038] Each tag in the adjusted Word document is configured into a numerical value according to the key-value pair mapping relationship as a data model of the tag, so as to obtain a configured Word document.
[0039] In this embodiment, each label in the adjusted Word document is configured as a data model, and a Map (a mapping relationship of a "key-value" pair) type can be used to pair labels and specific values to achieve rapid configuration of the adjusted Word document, which is convenient for subsequent generation of new documents based on the template engine. For example, if one of the mapping relationships of a "key-value" pair is that the label {{name}} corresponds to a value of 3, then the label {{name}} is converted into a value of 3 as the data model of the label. After the key-value pair mapping relationship of all labels in the adjusted Word document is configured into a value, the configured Word document can be obtained. In order to distinguish it from the value in the body text of the adjusted Word document, when the label is configured into a value according to the key-value pair mapping relationship, each configured value is added with a keylabel prefix. For example, after the label {{name}} is converted into a value of 3, keylabel is added before the value 3 to obtain a representation of keylabel3, thereby effectively distinguishing it from the numeric string in the text.
[0040] S103: Obtain a preset template engine, and load the configured Word document through the template engine to obtain an updated Word document.
[0041] In this embodiment, the preset template engine can adopt the POI-TL template engine (the full name of poi-tl is poitemplate language, which means Word template engine, and Word documents created using Word templates and data). After using the POI-TL template engine to load the configured Word document and associate it with the data model (that is, associate it with the data model corresponding to each tag in the adjusted Word document), the updated Word document can be obtained. In the process of the POI-TL template engine loading the configured Word document and associating it with the data model, the POI-TL template engine will automatically replace the entire tag in the docx format file with the specific value corresponding to the data model, thereby completing the entire conversion process. It can be seen that Word documents can be generated in Java by simply adding tags to the initial document and combining the POI-TL template engine, which improves the efficiency of generating Word documents.
[0042] In one embodiment, after step S103, the method further includes:
[0043] An output path is obtained, and the updated Word document is sent to a storage area corresponding to the output path for storage.
[0044] In this embodiment, when a Word document can be generated in Java based on the tagging method in the user terminal and combined with the POI-TL template engine, the updated Word document needs to be saved for subsequent viewing. At this time, it is only necessary to obtain the output path first, and send the updated Word document to the storage area corresponding to the output path for storage, which also ensures that the newly generated document is saved in time. In addition, the updated Word document can be uploaded to the server for cloud storage to further ensure data security.
[0045] This method can directly use an existing Word document as a template to generate a new document. It is no longer necessary to convert the Word document into an XML structure, which avoids errors that may be caused by the conversion process and improves the efficiency of generating Word documents in Java.
[0046] The embodiment of the present invention further provides a document generation device based on a template engine, and the document generation device based on a template engine is used to execute any embodiment of the document generation method based on a template engine. Figure 3 , Figure 3 It is a schematic block diagram of a document generation device 100 based on a template engine provided in an embodiment of the present invention.
[0047] Among them, Figure 3 As shown, the document generation device 100 based on the template engine includes a tag inserting unit 101 , a data model configuring unit 102 , and a template engine loading unit 103 .
[0048] The tag inserting unit 101 is used to obtain an initial Word document and a tag set, and insert each tag in the tag set into a corresponding position in the initial Word document according to the received tag insertion instruction to obtain an adjusted Word document.
[0049] In this embodiment, the technical solution is described with the user end as the execution subject. Each tag in the tag set includes a start identifier and an end identifier. When the user operates the user end to select an initial Word document and sets a tag set for the initial Word document, each tag in the tag set can be inserted into the corresponding position in the initial Word document, thereby realizing the preliminary editing of the initial Word document.
[0050] For example, a user can preliminarily write an initial Word document on the user side and insert a tag set. Tags in the tag set start with "{{" and end with "}}" (for example, "{{name}}" is a tag), and tags can appear in any position, including headers, footers, inside tables, and text boxes. Of course, for the above boundaries of the initial Word document, the style of the document will be completely retained, and the style of the tag will also be applied to the replaced text, where both the initial Word document and the adjusted Word document are docx format files. After completing the insertion of tags into the initial Word document, the first total number of tags in the adjusted Word document and the second total number of tags in the tag set can be counted respectively. If it is determined that the first total number and the second total number are equal, it means that all tags in the tag set are inserted into the initial Word document and the tag insertion is successfully completed. If it is determined that the first total number is less than the second total number, it means that there are tags in the tag set that have not been inserted into the initial Word document. At this time, a pop-up window can be issued to prompt the user whether to confirm the completion of the tag insertion. Only when the user selects to confirm the completion of the tag insertion can only some tags in the tag set be inserted into the initial Word document.
[0051] In one embodiment, the label inserting unit 101 includes:
[0052] The first type insertion unit is used for inserting the tag into the header of the initial Word document to obtain an adjusted Word document if it is determined that the tag is a header attribute tag;
[0053] The second type insertion unit is used for inserting the tag into the footer of the initial Word document to obtain an adjusted Word document if it is determined that the tag is a footer attribute tag;
[0054] A third type insertion unit is used for inserting the tag into the table in the initial Word document to obtain an adjusted Word document if it is determined that the tag is a table attribute tag;
[0055] The fourth type of insertion unit is used to insert the tag into the text box in the initial Word document to obtain an adjusted Word document if it is determined that the tag is a text box attribute tag.
[0056] In this embodiment, labels in the format of {{XXX}} can be inserted into the header, footer, inside the table, text box, etc. in the initial Word document, and each additional label in the initial Word document will update the initial Word document until the label editing is completed to obtain the final updated and saved adjusted Word document in the editing stage. In this way, based on the "what you see is what you get" feature of the template engine used later, the style of the document will be completely retained, and the style of the label will also be applied to the replaced text. Moreover, the label insertion process is simple and does not require complicated operations, which reduces the learning cost of operators and improves development efficiency.
[0057] The data model configuration unit 102 is used to configure the tags in the adjusted Word document into a data model according to a preset key-value pair mapping relationship to obtain a configured Word document.
[0058] In this embodiment, after the adjusted Word document is obtained, all tags therein need to be configured into a data model based on a preset key-value pair mapping relationship, that is, each tag is converted into a corresponding specific value, thereby obtaining a configured Word document.
[0059] In one embodiment, the data model configuration unit 102 is further configured to:
[0060] Each tag in the adjusted Word document is configured into a numerical value according to the key-value pair mapping relationship as a data model of the tag, so as to obtain a configured Word document.
[0061] In this embodiment, each label in the adjusted Word document is configured as a data model, and a Map (a mapping relationship of a "key-value" pair) type can be used to pair labels and specific values to achieve rapid configuration of the adjusted Word document, which is convenient for subsequent generation of new documents based on the template engine. For example, if one of the mapping relationships of a "key-value" pair is that the label {{name}} corresponds to a value of 3, then the label {{name}} is converted into a value of 3 as the data model of the label. After the key-value pair mapping relationship of all labels in the adjusted Word document is configured into a value, the configured Word document can be obtained. In order to distinguish it from the value in the body text of the adjusted Word document, when the label is configured into a value according to the key-value pair mapping relationship, each configured value is added with a keylabel prefix. For example, after the label {{name}} is converted into a value of 3, keylabel is added before the value 3 to obtain a representation of keylabel3, thereby effectively distinguishing it from the numeric string in the text.
[0062] The template engine loading unit 103 is used to obtain a preset template engine, load the configured Word document through the template engine, and obtain an updated Word document.
[0063] In this embodiment, the preset template engine can adopt the POI-TL template engine. After using the POI-TL template engine to load the configured Word document and associate the data model (that is, associate to the data model corresponding to each tag in the adjusted Word document), the updated Word document can be obtained. In the process of the POI-TL template engine loading the configured Word document and associating the data model, the POI-TL template engine will automatically replace the entire tag in the docx format file with the specific value corresponding to the data model, thereby completing the entire conversion process. It can be seen that the Word document can be generated in Java by simply adding tags to the initial document and combining the POI-TL template engine, which improves the efficiency of Word document generation.
[0064] In one embodiment, the document generation device 100 based on the template engine further includes:
[0065] The document output saving unit is used to obtain an output path and send the updated Word document to a storage area corresponding to the output path for storage.
[0066] In this embodiment, when a Word document can be generated in Java based on the tagging method in the user terminal and combined with the POI-TL template engine, the updated Word document needs to be saved for subsequent viewing. At this time, it is only necessary to obtain the output path first, and send the updated Word document to the storage area corresponding to the output path for storage, which also ensures that the newly generated document is saved in time. In addition, the updated Word document can be uploaded to the server for cloud storage to further ensure data security.
[0067] The device realizes the direct use of existing Word documents as templates to generate new documents. It is no longer necessary to convert the Word documents into XML structures, thus avoiding errors that may be caused by the conversion process and improving the efficiency of generating Word documents in Java.
[0068] The document generation device based on the template engine can be implemented in the form of a computer program. The computer program can be used in Figure 4 Runs on the computer device shown.
[0069] See also Figure 4 , Figure 4 5 is a schematic block diagram of a computer device provided in an embodiment of the present invention. The computer device 500 is a user terminal, which may be a smart phone, a desktop computer, a tablet computer, a laptop computer, etc.
[0070] See also Figure 4 The computer device 500 includes a processor 502 , a memory and a network interface 505 connected via a device bus 501 , wherein the memory may include a storage medium 503 and an internal memory 504 .
[0071] The storage medium 503 can store an operating device 5031 and a computer program 5032. When the computer program 5032 is executed, the processor 502 can execute a document generation method based on a template engine.
[0072] The processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500 .
[0073] The internal memory 504 provides an environment for the operation of the computer program 5032 in the storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a document generation method based on a template engine.
[0074] The network interface 505 is used for network communication, such as providing data information transmission, etc. Those skilled in the art will understand that Figure 4The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device 500 to which the solution of the present invention is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0075] The processor 502 is used to run the computer program 5032 stored in the memory to implement the document generation method based on the template engine disclosed in the embodiment of the present invention.
[0076] Those skilled in the art will understand that Figure 4 The embodiments of the computer device shown in the figure do not constitute a limitation on the specific composition of the computer device. In other embodiments, the computer device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, in some embodiments, the computer device may only include a memory and a processor. In such embodiments, the structure and function of the memory and the processor are the same as those of the embodiment of the present invention. Figure 4 The embodiments shown are consistent and will not be described again here.
[0077] It should be understood that in the embodiment of the present invention, the processor 502 may be a central processing unit (CPU), and the processor 502 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0078] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the document generation method based on the template engine disclosed in the embodiment of the present invention is implemented.
[0079] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the above-described equipment, devices and units can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. Those of ordinary skill in the art can appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to the function. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0080] In the several embodiments provided by the present invention, it should be understood that the disclosed equipment, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. Units with the same function may also be combined into one unit. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices or units, or may be electrical, mechanical or other forms of connection.
[0081] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present invention.
[0082] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0083] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a background server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), disk or CD-ROM and other media that can store program codes.
[0084] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A document generation method based on a template engine, characterized in that: include: Acquire an initial Word document and a tag set, and insert each tag in the tag set into a corresponding position in the initial Word document according to the received tag insertion instruction to obtain an adjusted Word document; The tags in the adjusted Word document are configured into a data model according to a preset key-value pair mapping relationship to obtain a configured Word document; as well as Obtain a preset template engine, and load the configured Word document through the template engine to obtain an updated Word document; The step of configuring the tags in the adjusted Word document into a data model according to a preset key-value pair mapping relationship to obtain a configured Word document includes: Obtain a data model by configuring each tag in the adjusted Word document into a numerical value according to the key-value pair mapping relationship to serve as the tag, and obtain a configured Word document; After getting the adjusted Word document, also include: Counting a first total number of tags in the adjusted Word document and a second total number of tags in the tag set; If it is determined that the first total number is equal to the second total number, it means that all tags in the tag set are inserted into the initial Word document and the tag insertion is successfully completed; If it is determined that the first total number is less than the second total number, it means that there are tags in the tag set that have not been inserted into the initial Word document, and a pop-up window is issued to prompt the user whether to confirm the completion of tag insertion.
2. The document generation method based on the template engine according to claim 1, characterized in that: Each tag in the tag set includes a start identifier and an end identifier.
3. The document generation method based on the template engine according to claim 2, characterized in that: The step of inserting each tag in the tag set into a corresponding position in the initial Word document according to the received tag insertion instruction to obtain an adjusted Word document includes: If it is determined that the tag is a header attribute tag, inserting the tag into the header of the initial Word document to obtain an adjusted Word document; If it is determined that the tag is a footer attribute tag, inserting the tag into the footer of the initial Word document to obtain an adjusted Word document; If it is determined that the tag is a table attribute tag, inserting the tag into the table in the initial Word document to obtain an adjusted Word document; If it is determined that the tag is a text box attribute tag, the tag is inserted into the text box in the initial Word document to obtain an adjusted Word document.
4. The document generation method based on the template engine according to claim 1, characterized in that: The method of obtaining a preset template engine and loading the configured Word document through the template engine to obtain an updated Word document further includes: An output path is obtained, and the updated Word document is sent to a storage area corresponding to the output path for storage.
5. A document generation device based on a template engine, characterized in that: include: A tag insertion unit, used to obtain an initial Word document and a tag set, and insert each tag in the tag set into a corresponding position in the initial Word document according to the received tag insertion instruction to obtain an adjusted Word document; A data model configuration unit, configured to configure the tags in the adjusted Word document into a data model according to a preset key-value pair mapping relationship to obtain a configured Word document; as well as A template engine loading unit, used to obtain a preset template engine, load the configured Word document through the template engine, and obtain an updated Word document; The data model configuration unit is also used for: Obtain a data model by configuring each tag in the adjusted Word document into a numerical value according to the key-value pair mapping relationship to serve as the tag, and obtain a configured Word document; After the label inserting unit, it also includes: Counting a first total number of tags in the adjusted Word document and a second total number of tags in the tag set; If it is determined that the first total number is equal to the second total number, it means that all tags in the tag set are inserted into the initial Word document and the tag insertion is successfully completed; If it is determined that the first total number is less than the second total number, it means that there are tags in the tag set that have not been inserted into the initial Word document, and a pop-up window is issued to prompt the user whether to confirm the completion of tag insertion.
6. The document generation device based on the template engine according to claim 5, characterized in that: Each tag in the tag set includes a start identifier and an end identifier.
7. The document generation device based on the template engine according to claim 6, characterized in that: The label inserting unit comprises: The first type insertion unit is used for inserting the tag into the header of the initial Word document to obtain an adjusted Word document if it is determined that the tag is a header attribute tag; The second type insertion unit is used for inserting the tag into the footer of the initial Word document to obtain an adjusted Word document if it is determined that the tag is a footer attribute tag; A third type insertion unit is used for inserting the tag into the table in the initial Word document to obtain an adjusted Word document if it is determined that the tag is a table attribute tag; The fourth type of insertion unit is used to insert the tag into the text box in the initial Word document to obtain an adjusted Word document if it is determined that the tag is a text box attribute tag.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the document generation method based on the template engine according to any one of claims 1 to 4 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, enables the processor to execute the document generation method based on a template engine according to any one of claims 1 to 4.
Citation Information
Patent Citations
Document generation method and system based on dynamic data
CN113449502A
