Method and system for generating report of multi-format template
By combining the key-value pair data format with report document syntax, multi-format reports are generated using the template engine, which solves the problems of difficult template modification, low data readability and single report type in the existing technology, and achieves efficient and easy-to-use reports generate.
Patent Information
- Application Number
- CN202411578530.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-07
- Publication Date
- 2024-12-06
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing report generation technology has problems such as difficulty in modifying templates, low data readability and transparency, and single report types, especially the high coupling between templates and data, and lacks traceability and ease of use.
The data format of key-value pairs is combined with the report document syntax, and the report template is loaded and rendered through the template engine to generate multi-format reports, including HTML and Word reports, and format creation and data filling are used using Jinja2 syntax, which supports arbitrary changes in template format and The key value placeholder of the data.
It greatly improves the readability and modifiability of the template, reduces the user demand cycle, ensures the traceability and transparency of data, supports the generation of multiple report types, and improves the process efficiency of report generation.
Smart Images

Figure CN119089887A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to a method and system for generating a report of a multi-format template. Background Art
[0002] Report generation is a common task in modern enterprise management and scientific research. In order to meet the needs of different users, it is usually necessary to generate reports in multiple formats, such as HTML reports and Word reports. Existing report generation technologies mainly include fixed template method: pre-define a fixed format report template and generate a report by filling in data. Script generation method: dynamically generate reports by writing scripts. Template engine method: use template engines (such as Jinja2, Velocity, etc.) to generate reports.
[0003] Although the above methods have met the needs of report generation to a certain extent, there are still some obvious limitations, such as difficulty in template modification, low data readability and transparency, and single report type.
[0004] In the Chinese patent document with publication number CN104657340A, an extensible script-based Word report generation system and method are disclosed, including a Word report template customization module, a Word report template conversion module, and a data access interface module. The Word report template customization module provides template customization specifications and performs error detection on the template customized by the user; the Word report template conversion module provides a scripted conversion process for the Word template written by the user, and finally generates an executable script file; the data access interface module defines how to access the data, and the script statement in the template obtains the report data source data through the data access interface. Although this patent document solves the problems of inflexible format control and inconvenient data processing to a certain extent, there are a large number of data access interfaces in the template, which have low readability and modifiability and are highly coupled with the data; the data lacks traceability in the entire report generation process, and only the data source and the data in the last generated report are not easy to maintain the report and track data problems, and only the word report template can be customized, which lacks ease of use. Summary of the invention
[0005] In view of the defects in the prior art, an object of the present invention is to provide a method and system for generating a report of a multi-format template.
[0006] A method for generating a report of a multi-format template according to the present invention comprises: Step S1: defining key-value pair information of report data according to user requirements; Step S2: Generate a report template according to the key-value pair information and the report format required by the user; Step S3: Rendering the report data onto the report template to generate a corresponding report.
[0007] Preferably, step S3 includes the following sub-steps: Step S3.1: defining a data format according to the key-value pair information, and obtaining corresponding report data from the data storage to generate a data file; Step S3.2: parsing the data file and extracting report data; Step S3.3: Loading the report template through the template engine; Step S3.4: Rendering the report data onto the loaded report template through the template engine to generate a corresponding report.
[0008] Preferably, the report template includes an HTML report template and a Word report template; if the report template is an HTML report template, the corresponding format is generated by HTML syntax and Jinja2 syntax according to customer requirements, Jinja2 is used for format creation, and corresponding placeholders are placed in the data part through Jinja2 syntax; if the report template is a Word report template, the Word syntax and the Jinja2 syntax of docx are used, and a key-value placeholder method is adopted.
[0009] Preferably, the report template can change its format arbitrarily, and all data are filled into corresponding positions in a key-value placeholder manner according to jinja2 syntax.
[0010] Preferably, step S3.1 includes creating a corresponding data structure according to the key-value pair information and obtaining an interface for the data structure, obtaining report data corresponding to the key-value pair information from the data storage, and generating a JSON data file of the key-value pair according to the report template.
[0011] Preferably, the step S3.2 includes processing the JSON data file by python and converting it into report data of a key-value pair structure of python.
[0012] Preferably, after processing the report data, the report template can load the template and render the data processing through the jinja template engine; the word report template uses the encapsulated jinja engine.
[0013] A system for generating a report with multiple template formats according to the present invention comprises: Module M1: Define the key-value pair information of report data according to user needs; Module M2: Generate a report template according to the key-value pair information and the report format required by the user; Module M3: Rendering the report data onto the report template to generate a corresponding report.
[0014] Preferably, the module M3 includes the following submodules: Module M3.1: define a data format according to the key-value pair information, obtain corresponding report data from the data storage, and generate a data file; Module M3.2: parsing the data file and extracting report data; Module M3.3: Loading the report template through the template engine; Module M3.4: Rendering the report data onto the loaded report template through the template engine to generate a corresponding report.
[0015] Preferably, the report template includes an HTML report template and a Word report template; if the report template is an HTML report template, the corresponding format is generated by HTML syntax and Jinja2 syntax according to customer requirements, Jinja2 is used for format creation, and corresponding placeholders are placed in the data part through Jinja2 syntax; if the report template is a Word report template, the Word syntax and the Jinja2 syntax of docx are used, and a key-value placeholder method is adopted.
[0016] Preferably, the report template can change its format arbitrarily, and all data are filled into corresponding positions in a key-value placeholder manner according to jinja2 syntax.
[0017] Preferably, the module M3.1 includes an interface for creating a corresponding data structure according to key-value pair information and obtaining the data structure, obtaining report data corresponding to the key-value pair information from the data storage, and generating a JSON data file of the key-value pair according to the report template.
[0018] Preferably, the module M3.2 includes processing the JSON data file through python and converting it into report data of the key-value pair structure of python.
[0019] Preferably, after processing the report data, the report template can load the template and render the data processing through the jinja template engine; the word report template uses the encapsulated jinja engine.
[0020] Compared with the prior art, the present invention has the following beneficial effects: 1. The present invention creates a template by combining the data format of key-value pairs with the syntax of the report document itself, which greatly improves the readability of the template and solves the problem of difficult modification and verification of report templates; and the JSON data of the key-value pairs can be directly modified without compiling the code to verify the report modification, which greatly reduces the user's demand cycle.
[0021] 2. The present invention solves the problem of readability and transparency of the entire data in report generation, ensures the traceability of data in the entire process and optimizes the process of generating data, reducing the use of various third-party script data interfaces.
[0022] 3. The present invention solves the problem of a single customizable report type by combining key values with corresponding type templates. It can also be applied to word reports and html reports, and has good practicality.
[0023] Other beneficial effects of the present invention will be explained in the specific implementation manner through the introduction of specific technical features and technical solutions. Through the introduction of these technical features and technical solutions, those skilled in the art should be able to understand the beneficial technical effects brought about by the technical features and technical solutions. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings: Figure 1 The present invention is a flow chart of the method. DETAILED DESCRIPTION
[0025] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0026] Reference Figure 1 As shown, a method for generating a report with multiple format templates includes: Step S1: defining key-value pair information of report data according to user requirements; Step S2: Generate a report template according to the key-value pair information and the report format required by the user; Step S3: Rendering the report data onto the report template to generate a corresponding report.
[0027] Step S3.1: Define the data format according to the key-value pair information, and obtain the corresponding report data from the data storage to generate a data file; specifically, create a corresponding data structure according to the key-value pair information and obtain the interface of the data structure, obtain the report data corresponding to the key-value pair information from the data storage, and generate a JSON data file of the key-value pair according to the report template.
[0028] Step S3.2: Parse the data file and extract the report data; for example, process the JSON data file through Python and convert it into report data of a key-value pair structure of Python.
[0029] Step S3.3: Loading the report template through the template engine; Step S3.4: Rendering the report data onto the loaded report template through the template engine to generate a corresponding report.
[0030] Report templates include HTML report templates and Word report templates. If the report template is HTML report template, the corresponding format is generated by HTML syntax and Jinja2 syntax according to customer requirements, and Jinja2 is used to create the format, and the corresponding placeholders are placed in the data part through Jinja2 syntax. If the report template is Word report template, the syntax of Word and the syntax of Jinja2 of Docx are used, and the key-value placeholder method is adopted. The report template can change its own format at will, and all data is filled in the corresponding position in the form of key-value placeholders according to Jinja2 syntax.
[0031] After processing the report data, the report template can load the template and render the data processing through the jinja template engine; the word report template uses the encapsulated jinja engine.
[0032] The present invention creates a template by combining the data format of key-value pairs with the syntax of the report document itself, which greatly improves the readability of the template and solves the problems of difficult modification and verification of report templates. It can also directly modify the JSON data of the key-value pairs without compiling the code to verify the report modification, greatly reducing the user's demand cycle.
[0033] The above is a basic embodiment of the present invention. The technical solution of the present invention is further described below through a preferred embodiment.
[0034] Example 1 Reference Figure 1 As shown, a method for generating a report with multiple format templates includes: Step 1: Define the key-value pair information of the report data according to user requirements.
[0035] Step 2: Generate a report template based on the key-value pairs and the user's required report format.
[0036] Report templates are mainly divided into two categories: HTML reports and word reports.
[0037] For HTML report templates, HTML syntax and Jinja2 template syntax are mainly used. According to customer requirements, HTML syntax and Jinja2 syntax are used to generate the corresponding format. The specific process is as follows: 1. The customer provides a UI report template based on his or her own report requirements. If the customer does not need to make major changes to the default template, he or she can provide the specific data and format that need to be modified.
[0038] 2. List the specific data information according to the UI report format provided by the customer. Create key values corresponding to the data according to the data to be displayed in the report. For example, coverage data can use key values such as coverageInfos:[{“coverage:”,”coverageType:”}] to represent coverage data.
[0039] 3. Based on the UI report style provided by the customer and the key values created, the developer manually generates the corresponding HTML report style according to the HTML syntax, and puts the corresponding data bits according to the Jinja2 syntax key values.
[0040] Since it is tedious to create HTML report templates manually, the use of Jinja2 in format creation can greatly speed up the creation of templates and avoid repeated creation of the same type of data template content. This process can be completed by using the loop code in Jinja2. After the format is created, the corresponding placeholders are placed in the data part through Jinja2 syntax. The placeholders are the corresponding key values in the JSON data file in step 2. The template is created.
[0041] The creation of a word report template is basically similar to that of html, using the syntax of word and the syntax of jinja2 of docx. Although there are differences with the jinja2 syntax of html, the key-value placeholder method is still used.
[0042] The formats of HTML templates and Word templates can be changed at will, and all data are filled into corresponding positions in the form of key-value placeholders according to Jinja2 syntax.
[0043] Step 3: According to the key-value pair, the data format is defined and the corresponding report data is obtained from the database to generate a JSON data file. To avoid the problem of large data volume, the specific data can be obtained from the database in advance according to the key-value information of the data and put into the memory for caching to avoid repeatedly obtaining the same type of data from the database. At the same time, the same type of big data can be processed in parallel by multiple threads to generate the corresponding key-value pair information.
[0044] Step 3.1: In step 1, the report template is generated and the key information in the report template is specified. According to the key information, a corresponding data structure and an interface for obtaining the data structure are created, and the report data corresponding to the key information is obtained from a data storage such as a database.
[0045] Step 3.2: Generate a JSON data file of key-value pairs based on the generated report data.
[0046] Step 4: Parse the JSON data file and extract the report data. In this embodiment, the JSON data file is processed by Python and converted into report data in a key-value pair structure of Python.
[0047] Step 5: Load the report template through the jinja2 template engine.
[0048] Step 6: Render the report data to the loaded report template through the jinja2 template engine to generate the corresponding report.
[0049] After processing the report data, all templates can be loaded and rendered through the jinja template engine. The word report template uses the encapsulated jinja engine to process word documents, which is consistent with the steps of jinja2 processing html templates. In addition, a logging function can be added to the report generation process to record problems in report generation. Important nodes of the generated JSON data file can be printed and saved, and the content when an error occurs can be redirected to the log file.
[0050] The present invention also provides a system for generating reports from multi-format templates. The system for generating reports from multi-format templates can be implemented by executing the process steps of the method for generating reports from multi-format templates, that is, those skilled in the art can understand the method for generating reports from multi-format templates as a preferred implementation of the system for generating reports from multi-format templates.
[0051] Specifically, a system for generating reports of multi-format templates includes: Module M1: Define the key-value pair information of report data according to user needs; Module M2: Generate a report template according to the key-value pair information and the report format required by the user; Module M3: Rendering the report data onto the report template to generate a corresponding report.
[0052] The module M3 includes the following submodules: Module M3.1: define a data format according to the key-value pair information, obtain corresponding report data from the data storage, and generate a data file; Module M3.2: parsing the data file and extracting report data; Module M3.3: Loading the report template through the template engine; Module M3.4: Rendering the report data onto the loaded report template through the template engine to generate a corresponding report.
[0053] The report templates include HTML report templates and Word report templates; if the report template is an HTML report template, the corresponding format is generated by HTML syntax and Jinja2 syntax according to customer requirements, Jinja2 is used for format creation, and the corresponding placeholders are placed in the data part through Jinja2 syntax; if the report template is a Word report template, the Word syntax and the Jinja2 syntax of Docx are used, and a key-value placeholder method is adopted.
[0054] The report template can change its format arbitrarily, and all data are filled into corresponding positions in the form of key-value placeholders according to Jinja2 syntax.
[0055] The module M3.1 includes an interface for creating a corresponding data structure according to key-value pair information and obtaining the data structure, obtaining report data corresponding to the key-value pair information from the data storage, and generating a JSON data file of the key-value pair according to the report template.
[0056] The module M3.2 includes processing JSON data files through Python and converting them into report data of Python key-value pair structure.
[0057] After processing the report data, the report template can load the template and render the data through the jinja template engine; the word report template uses the encapsulated jinja engine.
[0058] Those skilled in the art know that, in addition to realizing the system and its various devices, modules, and units provided by the present invention in a purely computer-readable program code, it is entirely possible to realize the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system and its various devices, modules, and units provided by the present invention can be considered as a hardware component, and the devices, modules, and units included therein for realizing various functions can also be regarded as structures within the hardware component; the devices, modules, and units for realizing various functions can also be regarded as both software modules for realizing the method and structures within the hardware component.
[0059] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A method for generating a report of a multi-format template, characterized in that: include: Step S1: defining key-value pair information of report data according to user requirements; Step S2: Generate a report template according to the key-value pair information and the report format required by the user; Step S3: Rendering the report data onto the report template to generate a corresponding report.
2. The method for generating a report of a multi-format template according to claim 1, characterized in that: The step S3 comprises the following sub-steps: Step S3.1: defining a data format according to the key-value pair information, and obtaining corresponding report data from the data storage to generate a data file; Step S3.2: parsing the data file and extracting report data; Step S3.3: Loading the report template through the template engine; Step S3.4: Rendering the report data onto the loaded report template through the template engine to generate a corresponding report.
3. The method for generating a report of a multi-format template according to claim 2, characterized in that: The report templates include HTML report templates and Word report templates; if the report template is an HTML report template, the corresponding format is generated by HTML syntax and Jinja2 syntax according to customer requirements, Jinja2 is used for format creation, and the corresponding placeholders are placed in the data part through Jinja2 syntax; if the report template is a Word report template, the Word syntax and the Jinja2 syntax of Docx are used, and a key-value placeholder method is adopted.
4. The method for generating a report of a multi-format template according to claim 3, characterized in that: The report template can change its format arbitrarily, and all data are filled into corresponding positions in the form of key-value placeholders according to Jinja2 syntax.
5. The method for generating a report of a multi-format template according to claim 3, characterized in that: The step S3.1 includes creating a corresponding data structure according to the key-value pair information and obtaining an interface for the data structure, obtaining report data corresponding to the key-value pair information from the data storage, and generating a JSON data file of the key-value pair according to the report template.
6. The method for generating a report of a multi-format template according to claim 3, characterized in that: The step S3.2 includes processing the JSON data file by python and converting it into report data of a key-value pair structure of python.
7. The method for generating a report of a multi-format template according to claim 3, characterized in that: After processing the report data, the report template can load the template and render the data through the jinja template engine; the word report template uses the encapsulated jinja engine.
8. A system for generating reports using multi-format templates, characterized in that: include: Module M1: Define the key-value pair information of report data according to user needs; Module M2: Generate a report template according to the key-value pair information and the report format required by the user; Module M3: Rendering the report data onto the report template to generate a corresponding report.
9. The system for generating reports using multi-format templates according to claim 8, characterized in that: The module M3 includes the following submodules: Module M3.1: define a data format according to the key-value pair information, obtain corresponding report data from the data storage, and generate a data file; Module M3.2: parsing the data file and extracting report data; Module M3.3: Loading the report template through the template engine; Module M3.4: Rendering the report data onto the loaded report template through the template engine to generate a corresponding report.
10. The system for generating reports using multi-format templates according to claim 9, characterized in that: The report templates include HTML report templates and Word report templates; if the report template is an HTML report template, the corresponding format is generated by HTML syntax and Jinja2 syntax according to customer requirements, Jinja2 is used for format creation, and the corresponding placeholders are placed in the data part through Jinja2 syntax; if the report template is a Word report template, the Word syntax and the Jinja2 syntax of Docx are used, and a key-value placeholder method is adopted.
Citation Information
Patent Citations
Expandable script-based Word report generating system and method
CN104657340A
Demand document template generation method and device, equipment and storage medium
CN113011151A
Report generation method and device
CN115618838A
Method, system, medium and equipment for automatically producing data analysis report
CN117851481A
