Automatic document generation method

By using bookmarks or special characters in the document to identify the data to be replaced, and combining the mapping technology of the data directory and JSON data format, the problem of long manual processing time and high error rate is solved, and the automatic generation of documents is achieved with high efficiency and accuracy.

CN118798146APending Publication Date: 2024-10-18CHENGDU YIZHIYI TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310996078.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-09
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

In the existing technology, manual processing of documents that are long and contain a lot of content but have a relatively fixed format takes a long time and is prone to errors.

Method used

Bookmarks or special characters are used to identify the location of the data to be replaced. Through label positioning, parsing and storage, data mapping in data directory and text mode is supported. APACHE POI is used to parse WORD documents. The data interface returns the JSON data format and is generated based on the Variables change the data mapping source to achieve flexible data replacement.

Benefits of technology

It greatly reduces the time for manual document processing, improves processing efficiency, reduces error rates, and achieves automation and accuracy of document generation through flexible data mapping.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118798146A_ABST
    Figure CN118798146A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic document generation method, which relates to the technical field of automatic document generation, and comprises the following steps: S1, template to-be-replaced data positioning: the process comprises a label positioning process, a label analysis process and a label storage process; s2, a data mapping process, wherein the process comprises label reading, data mapping and data format description; and S3, a document generation process, wherein a data mapping source can be changed according to the variable when the document is generated. The method is reasonable in design, and the to-be-replaced data of the template is positioned in a bookmark or special character mode to identify the position of the to-be-replaced data; the data mapping supports a data directory and a text mode, and the data directory represents a hierarchical relationship in a tree form; when the document is generated, the data mapping source can be changed according to the variable, so that the data mapping mode is more flexible.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of automatic document generation, and more specifically to the technical field of automatic document generation methods. Background Art

[0002] The template administrator first creates a document template and specifies the content to be replaced, including text, tables, graphs, charts, etc. The system automatically processes these elements into tags and maps data to these tags in a visual way. The document generator selects the completed document template and replaces the variables in the data mapping. After the replacement is completed, the system replaces the content in the document according to the data mapped by the tag to generate the document.

[0003] However, for documents that are long, contain a lot of content, but have a relatively fixed format, manual document processing takes a long time and is prone to errors.

[0004] How to solve the above technical problems has become the direction of efforts of those skilled in the art. Summary of the invention

[0005] The purpose of the present invention is to provide a method for automatically generating documents in order to solve the technical problem that the manual processing of existing documents with long length, various contents and relatively fixed formats is time-consuming and prone to errors.

[0006] In order to achieve the above-mentioned purpose, the present invention specifically adopts the following technical solutions: The present invention provides a method for automatically generating a document, comprising the following steps: S1. Positioning the data to be replaced in the template: This process includes the label positioning process, the label parsing process and the label storage process; S2, data mapping process: This process includes reading tags, data mapping, and data format description; S3, document generation process, when generating documents, the data mapping source can be changed according to the variables.

[0007] Specifically, the template locates the data to be replaced by using bookmarks or special characters to mark the location of the data to be replaced; data mapping supports data directories and text methods, and the data directory uses a tree to represent the hierarchical relationship. Its characteristics include supporting text, data interface, and FTP methods. The data interface returns support for the JSON data format, using "." to represent the JSON path; when the document is generated, the data mapping source can be changed according to the variable, making the data mapping method more flexible.

[0008] In one embodiment, in step S1, the label positioning process is to mark the location of the data to be replaced by using bookmarks or special characters; marking characters, tables, pictures and charts respectively; Among them, identification characters: italic characters, italic and underlined characters; Identification table: a table with identification characters in the data; Logo image: a picture with a bookmark; Logo chart: A chart that contains logo characters in the data.

[0009] In one embodiment, in step S1, the tag parsing process is to parse the WORD document using APACHE POI, read the paragraph data to determine whether it is the above tag; The identification character parsing method is as follows: 1) Get the document paragraph w:p; 2) w:r in the loop paragraph; 3) Get whether the style in w:r is italic or underlined; 4) If there is, save the current w:r; 5) Obtain other w:r in the paragraph in the same way as above. If their serial numbers are adjacent, they are considered to constitute a keyword together. If they are not adjacent, they are considered to be different keywords. The identification table is parsed as follows: 1) Get the table in the document; 2) Get the paragraph w:p in the table cell; 3) w:r in the loop paragraph; 4) Get whether the style in w:r is italic or underlined; 5) If there is, save the current w:r; 6) Get other w:r in the paragraph in the same way as above. If their serial numbers are adjacent, they are considered to form a keyword together. If they are not adjacent, they are considered to be different keywords. If there are multiple keywords in a cell, the table column to be replaced is considered to be increased by 1 column. 7) If there are multiple paragraphs in a cell and there are keywords in the paragraphs, the table row to be replaced is incremented by 1; 8) According to the above rows and columns, form a two-dimensional array of rows and columns that need to be replaced.

[0010] Among them, the identification chart analysis method is as follows: 1) Get the excel file corresponding to the chart; 2) Get whether the cell contains identification characters, and if so, record its row and column; 3) According to the above rows and columns, form a two-dimensional array of rows and columns that need to be replaced.

[0011] In one embodiment, in step S1, the tag storage process is to store the above tags by category, the text identification characters store the characters themselves, and the charts, pictures, and tables store their serial numbers according to their types in OOXML.

[0012] In one embodiment, in step S2, reading a tag: reading a data tag stored in a database; Data mapping: Data mapping supports data directory and text mode. The text mode is to directly set the value of the label to a certain text. The process of data directory mode is as follows: 1) The data directory uses a tree to represent the hierarchical relationship; 2) Data mapping can only map leaf nodes of the data directory; 3) The data directory node itself supports variables; 4) The data format of the leaf node is as follows: FTP mapping path description: The mapping path mainly processes data files stored in remote file mode and supports variable input, %FTP% / TEST / A / dealdata#PLAN; Among them, "FTP" is a variable, which needs to be set and replaced by the user when the document is generated; " / TEST / A / " is the file storage path; "Dealdata" is the data file name; "PLAN:" is the data block name, which mainly processes a data file and supports multiple tags, which are described and defined by wrapping the block name before and after; Text Mapping Instructions: Enter the data content to replace the label and supporting variables.

[0013] For example: %factory number%equipment%part number%version, where "factory number" and "part number" are variables and the user needs to set and replace them when the document is generated.

[0014] Data interface mapping description: The data interface returns a JSON object; Data format description: text is any character; picture is a base64 format string or a link address; table is a two-dimensional array; chart is a two-dimensional array.

[0015] In one embodiment, in step S3, the document generation process specifically includes the following steps: S31, select a template, select a template that has been made and data mapping has been completed; S32, replace variables. If there are variables in the data mapping, the variables are replaced in this step. The same variables only need to be replaced once. S33, read the data, and match the final data with the tag one by one according to the tag type and data mapping; S34, check the data, check whether the label data is empty, whether the format is correct, the picture must be base64 format data or binary data, the table and chart data must be a two-dimensional array, and consistent with the data column of the replaced table; S35. Replace the text, use OOXML to find the paragraph, find the corresponding tag in the paragraph, and replace the corresponding tag value; S36, replace the table, use OOXML to find the table with the same number as the tag table in the database, read the keyword array in the table, and obtain the value of the mapped two-dimensional array according to the row and column numbers of the keyword array for replacement. If the number of rows of the mapped data exceeds the original number of rows, the system will automatically add rows; S37, replace the image, use OOXML to find the image with the same sequence number as the label image in the database, replace the image with the corresponding value, and scale the new image in proportion to the original image size; S39. Replace the chart. Use OOXML to find the chart with the same label chart number in the database. Read the keyword array in the data table of the chart. Get the value of the mapped two-dimensional array according to the row and column numbers of the keyword array for replacement. If the number of rows of the mapped data exceeds the number of original rows, the system will automatically add rows. In addition, because the chart also includes type data and series data, it is necessary to regenerate new type data and series data according to the mapped data. S40, adding annotations, if the label data replacement is unsuccessful, adding annotations to the corresponding labels; S41. Generate a document and save the replaced template document as a new document.

[0016] The beneficial effects of the present invention are as follows: The present invention uses bookmarks or special characters to mark the location of data to be replaced; data mapping supports data directory and text methods, and the data directory uses a tree form to express the hierarchical relationship. It is characterized by supporting text, data interface, and FTP methods. The data interface returns support for JSON data format, and "." is used to represent the JSON path; when the document is generated, the data mapping source can be changed according to the variable, making the data mapping method more flexible. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 It is a flow chart of locating the data to be replaced in the template of the present invention; Figure 2 is a flow chart of the data mapping process of the present invention; Figure 3 It is a flowchart of the document generation process. Implementation

[0018] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, 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 described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0019] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. 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.

[0020] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings. In addition, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0021] In the description of the embodiments of the present invention, it should be noted that the terms "inside", "outside", "upper", etc. indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, or are the orientations or positional relationships in which the inventive product is usually placed when used. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention. Example

[0022] like Figures 1 to 3 As shown, this embodiment provides a method for automatically generating a document, comprising the following steps: S1. Positioning the data to be replaced in the template: This process includes the label positioning process, the label parsing process and the label storage process; The label positioning process is to mark the location of the data to be replaced by using bookmarks or special characters; marking characters, tables, pictures and charts respectively; Among them, identification characters: italic characters, italic and underlined characters; Identification table: a table with identification characters in the data; Logo image: a picture with a bookmark; Logo chart: A chart that contains logo characters in the data.

[0023] The tag parsing process is to use APACHE POI to parse the WORD document, read the paragraph data to determine whether it is the above tag; The identification character parsing method is as follows: 1) Get the document paragraph w:p; 2) w:r in the loop paragraph; 3) Get whether the style in w:r is italic or underlined; 4) If there is, save the current w:r; 5) Obtain other w:r in the paragraph in the same way as above. If their serial numbers are adjacent, they are considered to constitute a keyword together. If they are not adjacent, they are considered to be different keywords. The identification table is parsed as follows: 1) Get the table in the document; 2) Get the paragraph w:p in the table cell; 3) w:r in the loop paragraph; 4) Get whether the style in w:r is italic or underlined; 5) If there is, save the current w:r; 6) Get other w:r in the paragraph in the same way as above. If their serial numbers are adjacent, they are considered to form a keyword together. If they are not adjacent, they are considered to be different keywords. If there are multiple keywords in a cell, the table column to be replaced is considered to be increased by 1 column. 7) If there are multiple paragraphs in a cell and there are keywords in the paragraphs, the table row to be replaced is incremented by 1; 8) According to the above rows and columns, form a two-dimensional array of rows and columns that need to be replaced.

[0024] Among them, the identification chart analysis method is as follows: 1) Get the excel file corresponding to the chart; 2) Get whether the cell contains identification characters, and if so, record its row and column; 3) According to the above rows and columns, form a two-dimensional array of rows and columns that need to be replaced.

[0025] The tag storage process is to classify and store the above tags. Text identification characters store the characters themselves, and charts, pictures, and tables store their serial numbers according to their types in OOXML.

[0026] S2, data mapping process: This process includes reading tags, data mapping, and data format description; Read tags: read data tags stored in the database; Data mapping: Data mapping supports data directory and text mode. The text mode is to directly set the value of the label to a certain text. The process of data directory mode is as follows: 1) The data directory uses a tree to represent the hierarchical relationship; 2) Data mapping can only map leaf nodes of the data directory; 3) The data directory node itself supports variables; 4) The data format of the leaf node is as follows: FTP mapping path description: The mapping path mainly processes data files stored in remote file mode and supports variable input, %FTP% / TEST / A / dealdata#PLAN; Among them, "FTP" is a variable, which needs to be set and replaced by the user when the document is generated; " / TEST / A / " is the file storage path; "Dealdata" is the data file name; "PLAN:" is the data block name, which mainly processes a data file and supports multiple tags, which are described and defined by wrapping the block name before and after; Text Mapping Instructions: Enter the data content to replace the label and supporting variables.

[0027] For example: %factory number%equipment%part number%version, where "factory number" and "part number" are variables and the user needs to set and replace them when the document is generated.

[0028] Data interface mapping description: The data interface returns a JSON object; Data format description: text is any character; picture is a base64 format string or a link address; table is a two-dimensional array; chart is a two-dimensional array.

[0029] S3, document generation process, when generating documents, the data mapping source can be changed according to the variables.

[0030] The document generation process specifically includes the following steps: S31, select a template, select a template that has been made and data mapping has been completed; S32, replace variables. If there are variables in the data mapping, the variables are replaced in this step. The same variables only need to be replaced once. S33, read the data, and match the final data with the tag one by one according to the tag type and data mapping; S34, check the data, check whether the label data is empty, whether the format is correct, the picture must be base64 format data or binary data, the table and chart data must be a two-dimensional array, and consistent with the data column of the replaced table; S35. Replace the text, use OOXML to find the paragraph, find the corresponding tag in the paragraph, and replace the corresponding tag value; S36, replace the table, use OOXML to find the table with the same number as the tag table in the database, read the keyword array in the table, and obtain the value of the mapped two-dimensional array according to the row and column numbers of the keyword array for replacement. If the number of rows of the mapped data exceeds the original number of rows, the system will automatically add rows; S37, replace the image, use OOXML to find the image with the same sequence number as the label image in the database, replace the image with the corresponding value, and scale the new image in proportion to the original image size; S39. Replace the chart. Use OOXML to find the chart with the same label chart number in the database. Read the keyword array in the data table of the chart. Get the value of the mapped two-dimensional array according to the row and column numbers of the keyword array for replacement. If the number of rows of the mapped data exceeds the number of original rows, the system will automatically add rows. In addition, because the chart also includes type data and series data, it is necessary to regenerate new type data and series data according to the mapped data. S40, adding annotations, if the label data replacement is unsuccessful, adding annotations to the corresponding labels; S41. Generate a document and save the replaced template document as a new document.

Claims

1. A method for automatically generating a document, characterized in that: The steps include: S1. Positioning the data to be replaced in the template: This process includes the label positioning process, the label parsing process and the label storage process; S2, data mapping process: This process includes reading tags, data mapping, and data format description; S3. Document generation process: When generating documents, the data mapping source can be changed according to the variables.

2. A method for automatically generating documents according to claim 1, characterized in that: In step S1, the label positioning process is to mark the location of the data to be replaced by using bookmarks or special characters; marking characters, tables, pictures and charts respectively; Among them, identification characters: italic characters, italic and underlined characters; Identification table: a table with identification characters in the data; Logo image: a picture with a bookmark; Logo chart: A chart that contains logo characters in the data.

3. A method for automatically generating documents according to claim 2, characterized in that: In step S1, the tag parsing process is to parse the WORD document using APACHE POI, read the paragraph data to determine whether it is the above tag; The identification character parsing method is as follows: 1) Get the document paragraph w:p; 2) w:r in the loop paragraph; 3) Get whether the style in w:r is italic or underlined; 4) If there is, save the current w:r; 5) Obtain other w:r in the paragraph in the same way as above. If their serial numbers are adjacent, they are considered to constitute a keyword together. If they are not adjacent, they are considered to be different keywords. The identification table is parsed as follows: 1) Get the table in the document; 2) Get the paragraph w:p in the table cell; 3) w:r in the loop paragraph; 4) Get whether the style in w:r is italic or underlined; 5) If there is, save the current w:r; 6) Get other w:r in the paragraph in the same way as above. If their serial numbers are adjacent, they are considered to form a keyword together. If they are not adjacent, they are considered to be different keywords. If there are multiple keywords in a cell, the table column to be replaced is considered to be increased by 1 column. 7) If there are multiple paragraphs in a cell and there are keywords in the paragraphs, the table row to be replaced is incremented by 1; 8) According to the above rows and columns, form a two-dimensional array of rows and columns to be replaced; Among them, the identification chart analysis method is as follows: 1) Get the excel file corresponding to the chart; 2) Get whether the cell contains identification characters, and if so, record its row and column; 3) According to the above rows and columns, form a two-dimensional array of rows and columns that need to be replaced.

4. A method for automatically generating documents according to claim 3, characterized in that: In step S1, the tag storage process is to classify and store the above tags, store the characters themselves for text identification characters, and store the serial numbers of charts, pictures, and tables according to their types in OOXML.

5. A method for automatically generating documents according to claim 4, characterized in that: In step S2, read the tag: read the data tag stored in the database; Data mapping: Data mapping supports data directory and text methods. The data directory method process is as follows: 1) The data directory uses a tree to represent the hierarchical relationship; 2) Data mapping can only map leaf nodes of the data directory; 3) The data directory node itself supports variables; Text Mapping Instructions: Enter the data content to replace the label and supporting variables.

6. A method for automatically generating documents according to claim 5, characterized in that: In step S3, the document generation process specifically includes the following steps: S31, select a template, select a template that has been made and data mapping has been completed; S32, replace variables. If there are variables in the data mapping, the variables are replaced in this step. The same variables only need to be replaced once. S33, read the data, and match the final data with the tag one by one according to the tag type and data mapping; S34, check the data, check whether the label data is empty, whether the format is correct, the picture must be base64 format data or binary data, the table and chart data must be a two-dimensional array, and consistent with the data column of the replaced table; S35. Replace the text, use OOXML to find the paragraph, find the corresponding tag in the paragraph, and replace the corresponding tag value; S36, replace the table, use OOXML to find the table with the same number as the tag table in the database, read the keyword array in the table, and obtain the value of the mapped two-dimensional array according to the row and column numbers of the keyword array for replacement. If the number of rows of the mapped data exceeds the original number of rows, the system will automatically add rows; S37, replace the image, use OOXML to find the image with the same sequence number as the label image in the database, replace the image with the corresponding value, and scale the new image in proportion to the original image size; S39. Replace the chart. Use OOXML to find the chart with the same label chart number in the database. Read the keyword array in the data table of the chart. Get the value of the mapped two-dimensional array according to the row and column numbers of the keyword array for replacement. If the number of rows of the mapped data exceeds the number of original rows, the system will automatically add rows. In addition, because the chart also includes type data and series data, it is necessary to regenerate new type data and series data according to the mapped data. S40, adding annotations, if the label data replacement is unsuccessful, adding annotations to the corresponding labels; S41. Generate a document and save the replaced template document as a new document.

Citation Information

Cited By

  • Template filling method and system based on expression value and bookmark positioning

    CN122572410A