Method for automatically generating document
By using XML and JSON files to record the static and dynamic content of document templates, the problem of unified and flexible adjustment of document formats is solved, and standardized document generation and low-cost maintenance are achieved.
Patent Information
- Application Number
- CN202410753449.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-10-08
AI Technical Summary
The existing technology makes it difficult to flexibly adjust document templates while ensuring uniform standards and rigor in document formats, and small changes require adjustment of program codes, resulting in high maintenance costs.
XML and JSON files are used to record the static and dynamic content of the document template respectively. The dynamic content is represented by variable identifiers. Users can replace the content according to their needs to generate standardized documents and avoid modifying the program code.
It achieves a unified standard and rigorous format for documents, while lowering the threshold for template changes and reducing maintenance costs.
Smart Images

Figure CN118747495A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of algorithms, and in particular to a method for automatically generating documents. Background Art
[0002] With the continuous advancement of information technology, the online office model has been adopted by more and more employees, which has greatly improved the flexibility and convenience of work, eliminated the constraints of geographical location on collaboration, and significantly reduced the accommodation and transportation costs caused by business trips. However, this change has brought new challenges: a large number of work records, including but not limited to meeting minutes, employee information, voting resolutions, discussion records and other key information, are stored in various database systems in digital form. When there is a need to convert these electronic information into traditional paper files, the difficulty of operation increases significantly, which not only increases the workload of manpower in organizing paper documents, but also makes it difficult to ensure the uniformity of the writing format of the same type of documents.
[0003] In the prior art, one approach is to design a highly customized visual interface that allows users to set details such as font style, paragraph layout, and signature style according to their specific needs. However, this approach gives users too much freedom, which may result in different styles of documents generated, making it difficult to meet the unified standards and strict format requirements required by laws and regulations. Another approach is for the R&D team to directly manage and preset templates at the system program level based on specific needs, without the need for users or operation and maintenance personnel to intervene in too much editing process. Nevertheless, under this method, any minor template changes require adjustments to the program code, which lacks flexibility, and the cost of each update and maintenance is relatively high. Summary of the invention
[0004] In order to simplify the document production process and generate a standardized template conveniently and quickly, an embodiment of the present invention provides a method for generating a document, comprising the following steps:
[0005] S1: According to user needs, a document template file is created for a type of document, and the document template file includes a first template file and a second template file; the first template file records the static content and dynamic content of the document, and the dynamic content is represented in the form of variable identifiers; the second template file records the value source of each variable identifier in the corresponding first template file, and the value source includes data of the document generation scene or data of the database;
[0006] S2: According to the user's instructions, select the specified document template file, and according to the content of the second template file, obtain the values of all variable identifiers in the first template from the data or database of the current document generation scenario, and replace the corresponding content of the first template, and then convert the content of the first template file into the format required by the document, thereby obtaining the required document.
[0007] Preferably, the static content includes fixed text and format information of this type of document.
[0008] Preferably, the dynamic content includes personalized text and format information of this type of document.
[0009] Preferably, the format information includes bookmark information.
[0010] Preferably, the first template file is expressed in the form of an XML file; and the second template file is expressed in the form of a JSON file.
[0011] Beneficial effect: The method of the present invention is used to generate documents, which can ensure that the generated documents have uniform standards and strict format requirements; at the same time, when the document template needs to be changed, the document template can be changed with a lower threshold and without modifying the program code, only the XML file and the JSON file need to be modified to achieve the change. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Figure 1 is a flow chart of the present invention; DETAILED DESCRIPTION
[0013] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below 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.
[0014] like Figure 1 As shown, a method for automatically generating a document comprises the following steps:
[0015] S1: According to user needs, a document template file is prepared for a type of document, and the document template file includes a first template file and a second template file; the first template file records the static content and dynamic content of the document, the static content includes the fixed text of the document and the format information such as font size, color, bookmarks, etc., and the dynamic content includes the personalized text and format information of the document, and the dynamic content is represented in the form of variable identifiers; the second template file records the value source of each variable identifier in the corresponding first template file, and the value source includes the data of the document generation scene or the data of the database;
[0016] In this embodiment, the first template file is represented in the form of an XML file. In specific operations, a document template can be directly made using a word document and then saved as an XML file; the second template file is represented in the form of a JSON file, which records the value sources of each variable identifier in the first template file, and the value sources include data of the document generation scenario or data of the database; for example, the value of a variable identifier is recorded as the name of the organization where the current user is located, or the value of a variable identifier is recorded as the names of all participants in the current project;
[0017] JSON (JavaScript Object Notation) is a lightweight data exchange format that represents data in an easy-to-read and easy-to-write text format.
[0018] XML (eXtensible Markup Language) is a markup language used to describe and transmit data. It consists of tags, attributes, and data. Tags are used to define elements in a document, attributes are used to describe the characteristics of these elements, and data is used to contain specific content. XML language is very flexible and can define and extend its own tags and attributes, so it is widely used in various applications and platforms. JSON data is organized in the form of key-value pairs, which is easy to understand and write.
[0019] S2: According to the user's instructions, select the specified document template file, and according to the content of the second template file, obtain the values of all variable identifiers in the first template from the data or database of the current document generation scenario, and replace the corresponding content of the first template, and then convert the content of the first template file into the format required by the document, thereby obtaining the required document.
[0020] In the document generated by the present invention, the dynamic content includes format information, which can create convenience for other programs to process the document generated by the present invention. For example, in the present embodiment, in the first template file, a variable identifier is used to fill in the signature form of each signatory. According to the information of the second template file, the signature form of each signatory of this case is filled in order at the variable identifier, and a bookmark is inserted in the signature position of the signature form; when the subsequent electronic signature program processes the document, it can automatically locate the signature position of each signatory according to the bookmark position in the document, and accurately insert the signature content.
[0021] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for automatically generating a document, characterized in that: The following steps are involved: S1: According to user needs, a document template file is created for a type of document, and the document template file includes a first template file and a second template file; the first template file records the static content and dynamic content of the document, and the dynamic content is represented in the form of variable identifiers; the second template file records the value source of each variable identifier in the corresponding first template file, and the value source includes data of the document generation scene or data of the database; S2: According to the user's instructions, select the specified document template file, and according to the content of the second template file, obtain the values of all variable identifiers in the first template from the data or database of the current document generation scenario, and replace the corresponding content of the first template, and then convert the content of the first template file into the format required by the document, thereby obtaining the required document.
2. The method for automatically generating a document according to claim 1, characterized in that: The static content includes fixed text and format information of this type of document.
3. The method for automatically generating documents according to claim 1, characterized in that: The dynamic content includes personalized text and format information of this type of document.
4. A method for automatically generating documents according to any one of claims 2 or 3, characterized in that: The format information includes bookmark information.
5. The method for automatically generating documents according to claim 1, characterized in that: The first template file is expressed in the form of an XML file; the second template file is expressed in the form of a JSON file.
